【问题标题】:How can I make a bot join a specific voice channel? (discord.py)如何让机器人加入特定的语音频道? (discord.py)
【发布时间】:2020-10-04 08:10:37
【问题描述】:

我正在尝试制作一个不和谐机器人,当被调用时,它会加入作者所在的语音频道。

这是我所拥有的:

@client.command(aliases=["join"])
async def join_voice(self, ctx):
    channel = ctx.author.voice.channel
    if channel:
        print(channel.id)
        await channel.connect()

当我加入语音频道并输入命令时,我收到此错误:

Ignoring exception in command join_voice:
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 790, in invoke
    await self.prepare(ctx)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 751, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 670, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 516, in transform
    raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.

【问题讨论】:

    标签: bots discord discord.py


    【解决方案1】:

    此命令是否位于 cog/extension 中?看起来上下文是作为 self 传递的,仅当函数是类函数时才需要。如果您在主文件中声明此命令,您只需将签名设为 async def join_voice(ctx):

    【讨论】:

      猜你喜欢
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2018-06-16
      • 2020-10-15
      • 1970-01-01
      • 2019-05-05
      相关资源
      最近更新 更多