【问题标题】:adding a discord.py bot to a voice channel将 discord.py 机器人添加到语音通道
【发布时间】:2021-07-08 05:26:58
【问题描述】:

我正在尝试使用 discord.py 将我的机器人连接到语音频道,但它对我来说效果不佳...关于如何改进它的任何帮助?

    @bot.command(pass_context=True)
    async def join(ctx):
        channel = ctx.author.voice.channel
        await bot.join_voice_channel(channel)

错误:

    Ignoring exception in command join:
    Traceback (most recent call last):
      File "C:\Users\matan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 85, in wrapped
        ret = await coro(*args, **kwargs)
      File "C:/Users/matan/Desktop/python/discord bot 1/Main.py", line 926, in join
        await bot.join_voice_channel(channel)
    AttributeError: 'Bot' object has no attribute 'join_voice_channel'

我也有这个代码:

    @bot.command()
    async def play(ctx, url : str, channel = discord.VoiceChannel):
        await channel.connect()

它没有错误 - 它只是什么都不做......

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

要加入您使用的频道await VoiceChannel.connect()

所以你的例子是

@bot.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()

pass_context 也已弃用 afaik。

第二个例子

@bot.command()
async def play(ctx, url: str, channel: discord.VoiceChannel):
    await channel.connect()

我猜只是一个错字,你必须使用: 来声明参数类型。

【讨论】:

  • 我收到第一个错误:Ignoring exception in command join: Traceback (most recent call last): File "C:\Users\matan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "C:/Users/matan/Desktop/python/discord bot 1/Main.py", line 926, in join await bot.join_voice_channel(channel) AttributeError: 'Bot' object has no attribute 'join_voice_channel'
  • 抱歉复制了我编辑的错误代码,现在应该可以了。
猜你喜欢
  • 2019-12-11
  • 2018-06-16
  • 2020-08-30
  • 2019-04-08
  • 2020-12-30
  • 2021-07-04
  • 1970-01-01
  • 2020-09-06
  • 2022-01-04
相关资源
最近更新 更多