【问题标题】:Python - How do I make a join commandPython - 如何创建连接命令
【发布时间】:2019-08-24 01:48:40
【问题描述】:

我正在尝试为我的机器人创建一个“.join”命令,但我尝试过的所有方法都不起作用并且我尝试了很多方法

这是我尝试过的,我也尝试过其他几种方式:

@client.command(pass_context=True)
async def join(ctx):
 channel=ctx.message.author.voice.VoiceChannel

 await client.join_VoiceChannel(channel)

它给出了这个错误: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'VoiceState' object has no attribute 'VoiceChannel'

【问题讨论】:

  • this answer 适合您吗?我相信你打电话给 author.voice.VoiceChannel 应该只是打电话给 author.VoiceChannel
  • 我现在收到此错误 discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Member' object has no attribute 'voice_channel' 和 author.VoiceChannel 相同

标签: python-3.x discord.py discord.py-rewrite


【解决方案1】:
join_voice_channel

适用于旧版本的 discord.py

这个代码块应该可以工作:

@client.command(pass_context=True)
async def join(ctx):
    message = ctx.message
    channel_id = ctx.message.author.voice.channel.id
    channel = client.get_channel(channel_id)
    await channel.connect()

【讨论】:

    【解决方案2】:

    您使用join_voice_channel 让机器人加入语音频道,正如它在Async docs 中所说的那样 试试这个:

    @client.command(pass_context=True)
    async def join(ctx):
        author=ctx.message.author
        await bot.join_voice_channel(author.voice_channel)
    

    【讨论】:

    • Bot has no attribute join_voice_channel 是我得到的错误
    • 您确定您使用的是异步吗?您可能已经安装了重写。在python中输入import discord;print(discord.__version__)来检查你的版本或discord.py,如果异步然后idk脚本有什么问题如果重写那么你的脚本是错误的,如果给出的版本是1.0.0或更高,那么你正在使用重写,但如果它小于 1.0.0 则它是异步的(另外我建议你使用重写)
    • 我正在使用重写,我喜欢保持最新
    猜你喜欢
    • 2013-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 2016-06-15
    • 1970-01-01
    相关资源
    最近更新 更多