我正在尝试创建一个不和谐的机器人,该机器人在被调用时将加入作者所在的语音通道。
这就是我所拥有的:
@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.
答案 0 :(得分:1)
此命令是否位于齿轮/扩展名中?看起来上下文是作为自身传递的,这仅在函数是类函数时才需要。如果您在主文件中声明此命令,则只需将签名设为
async def join_voice(ctx):