不和谐中缺少参数消息
missing arguments message in discord
所以我用不同的帮助菜单制作了一个帮助命令。就像mee6一样。但我想添加一条消息,因为没有给出任何参数。怎么做?这是我现在拥有的:
@bot.command(name='help')
async def help(ctx, *, content):
if content == ('Moderation'):
await ctx.send(moderationmenu)
if content == ('fun'):
await ctx.send(funmenu)
if content == None:
await ctx.send('please provide an argument (Moderation / fun)')
您可以像这样提供默认 arg 值:
@bot.command(name="help")
async def help(ctx, *, content = None):
if not content: # more pythonic way of checking a variable is None or not
await ctx.send("Please provide an argument (moderation / fun)")
elif content.lower() == "fun": # brackets not necessary
await ctx.send(funmenu)
elif content.lower() == "moderation": # makes it case insensitive
await ctx.send(moderationmenu)
else:
await ctx.send("Sorry, I didn't recognise that category. Please choose (moderation / fun)")
快速编辑 - 如果您将菜单分类为单独的变量,则可以将它们映射到字典中:
@bot.command(name="help")
async def help(ctx, *, content = None):
menus = {"fun": funmenu, "moderation": moderationmenu}
if not content:
await ctx.send("Please provide an argument (moderation / fun)")
else:
try:
await ctx.send(menus[content.lower()])
except KeyError:
await ctx.send("Sorry, I didn't recognise that category. Please choose (moderation / fun)")
参考文献:
所以我用不同的帮助菜单制作了一个帮助命令。就像mee6一样。但我想添加一条消息,因为没有给出任何参数。怎么做?这是我现在拥有的:
@bot.command(name='help')
async def help(ctx, *, content):
if content == ('Moderation'):
await ctx.send(moderationmenu)
if content == ('fun'):
await ctx.send(funmenu)
if content == None:
await ctx.send('please provide an argument (Moderation / fun)')
您可以像这样提供默认 arg 值:
@bot.command(name="help")
async def help(ctx, *, content = None):
if not content: # more pythonic way of checking a variable is None or not
await ctx.send("Please provide an argument (moderation / fun)")
elif content.lower() == "fun": # brackets not necessary
await ctx.send(funmenu)
elif content.lower() == "moderation": # makes it case insensitive
await ctx.send(moderationmenu)
else:
await ctx.send("Sorry, I didn't recognise that category. Please choose (moderation / fun)")
快速编辑 - 如果您将菜单分类为单独的变量,则可以将它们映射到字典中:
@bot.command(name="help")
async def help(ctx, *, content = None):
menus = {"fun": funmenu, "moderation": moderationmenu}
if not content:
await ctx.send("Please provide an argument (moderation / fun)")
else:
try:
await ctx.send(menus[content.lower()])
except KeyError:
await ctx.send("Sorry, I didn't recognise that category. Please choose (moderation / fun)")
参考文献: