我正在尝试制作一个简单的音乐机器人。当我执行命令时,我得到一个错误:Ctx是缺少的必需参数
import discord
from discord.ext import commands
import asyncio
bot = commands.Bot(command_prefix= "-")
class VoiceConnectionError(commands.CommandError):
"""Custom Exception class for connection errors."""
class InvalidVoiceChannel(VoiceConnectionError):
"""Exception for cases of invalid Voice Channels."""
@bot.event
async def on_ready():
print('Bot ready')
@bot.command(name='connect', aliases=['join'], pass_context=True)
async def connect(self, ctx, *, channel: discord.VoiceChannel=None):
await ctx.send(f'Connected to: **{channel}**', delete_after=10)
bot.run('TOKEN')
该命令应将漫游器不一致地移入语音通道。
完整回溯: 忽略命令连接中的异常: 追溯(最近一次通话): 调用中的文件“ /anaconda3/lib/python3.6/site-packages/discord/ext/commands/bot.py”,行859 等待ctx.command.invoke(ctx) 调用中的文件“ /anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py”,第718行 等待self.prepare(ctx) 准备文件“ /anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py”,行682 等待自我._parse_arguments(ctx) _parse_arguments中的文件“ /anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py”,第596行 转换=等待self.transform(ctx,param) 转换中的文件“ /anaconda3/lib/python3.6/site-packages/discord/ext/commands/core.py”,第442行 引发MissingRequiredArgument(param) discord.ext.commands.errors.MissingRequiredArgument:ctx是缺少的必需参数。
答案 0 :(得分:0)
您的命令只有part of a cog才应接受self
参数。删除参数:
@bot.command(name='connect', aliases=['join'], pass_context=True)
async def connect(ctx, *, channel: discord.VoiceChannel=None):
...