discord.ext.commands.errors.MissingRequiredArgument:ctx是缺少的必需参数

时间:2020-09-24 23:32:00

标签: python discord discord.py

#help command
@client.command()
async def help(prefix, ctx, type_help = "None"):
  author = ctx.message.author
  if type_help == "None":
    embed = discord.Embed(title = "Help Command", value = "Welcome to the Help Command. Look at the various categories the bot has to offer! If there is a <> it is optional! Also if there is a [], that is required. This bot is made by ! bobthefam#6969", color=discord.Colour.blue())
    embed.add_field(name = f"``{prefix}polls``", value = "", inline = False)
  else:
    embed = discord.Embed(title = "Oops", description = "I think you may have misspelled something. Try again")
            
  await ctx.channel.send(author, embed = embed)

我得到标题错误。我该如何解决?

1 个答案:

答案 0 :(得分:1)

this页上,您可以看到实际函数不带前缀,而实际上是命令。

您的代码应具有以下内容:


client = commands.Bot(command_prefix='!')

@client.command() # !help for invoke the command
async def help(ctx, type_help = "None"):
  author = ctx.message.author
  [...]

documentation中,您可以通过为command_prefix变量使用可调用的(只是说一个函数的好方法;)来创建动态前缀

我猜是这样的

def my_custom_prefix(bot, message):
  # bot.commands contain all available commands
  matching_command = [command.name for command in bot.commands if command.name in message]
  if matching_command:
     return message.split(matching_command[0])[0]
  return "!" # I guess you need a default prefix in case

client = commands.Bot(command_prefix=my_custom_prefix, case_insensitive=True)

@client.command() # {whatever_you_want_by_default_!}help for invoke the command
async def help(ctx, type_help = "None"):
  author = ctx.message.author
  [...]