您如何确保用户在 discord.py 中键入了完整的命令?
How do you make sure that user types full command in discord.py?
看看这个例子:
@client.command()
async def redeem(ctx, code):
if code in available_codes:
await ctx.reply("you redeemed the code!")
else:
await ctx.reply("It does not exist")
或者如果你使用齿轮和东西:
@commands.command()
async def redeem(self, ctx: commands.Context, code: str)
if code in available_codes:
await ctx.reply("you redeemed the code!")
else:
await ctx.reply("It does not exist')
两者是一样的...
如果一个人不输入代码,则什么也不会发生...
如果有人不输入验证码,您如何发送消息?我试过了:
if code == "":
await ctx.reply("please specify a code")
但它不起作用...如果您不输入代码,则什么也不会发生,就好像上面那行根本不存在一样。那么如果没有指定代码,如何执行操作呢?或者至少,您如何确保至少告知用户输入代码?
您可以给参数一个默认值。
async def redeem(ctx, code=""):
if code == "":
await ctx.reply("please specify a code")
看看这个例子:
@client.command()
async def redeem(ctx, code):
if code in available_codes:
await ctx.reply("you redeemed the code!")
else:
await ctx.reply("It does not exist")
或者如果你使用齿轮和东西:
@commands.command()
async def redeem(self, ctx: commands.Context, code: str)
if code in available_codes:
await ctx.reply("you redeemed the code!")
else:
await ctx.reply("It does not exist')
两者是一样的...
如果一个人不输入代码,则什么也不会发生...
如果有人不输入验证码,您如何发送消息?我试过了:
if code == "":
await ctx.reply("please specify a code")
但它不起作用...如果您不输入代码,则什么也不会发生,就好像上面那行根本不存在一样。那么如果没有指定代码,如何执行操作呢?或者至少,您如何确保至少告知用户输入代码?
您可以给参数一个默认值。
async def redeem(ctx, code=""):
if code == "":
await ctx.reply("please specify a code")