我创建了一个机器人,当用 ?give {arg} 命令时,将输出 {arg} has been given!。但是,我添加了一些会输出不同消息的特定食物(例如拉面会输出拉面的图像),但是,因为它在技术上仍然是一个 arg,机器人会输出这两条消息,我该如何编码它以便如果arg 是特定食物之一,机器人只会输出该特定信息?我的代码目前:@client.command()async def give(ctx, arg, member: discord.Member = None, case_insensitive=True): if arg == 'lumpia': if member: username = ctx.message.author.display_name name = member.display_name embed = discord.Embed(title=(f'{username} has given lumpia to {name}!'), description =('{|__|}\n( • . •)\n/ >🥖' ), color=0x83B5E3) embed.set_image(url='https://images.summitmedia-digital.com/yummyph/images/2019/10/26/porkandshrimplumpiarecipe2.jpg') else: embed = discord.Embed(title=('Lumpia has been given!'), description=('{|__|}\n( • . •)\n/ >🥖' ), color=0x83B5E3) embed.set_image(url = 'https://images.summitmedia-digital.com/yummyph/images/2019/10/26/porkandshrimplumpiarecipe2.jpg') await ctx.send(embed=embed) if arg == 'ramen': if member: username = ctx.message.author.display_name name = member.display_name embed = discord.Embed(title=(f'{username} has given a bowl of ramen to {name}!'), description=('{|__|}\n( • . •)\n/ >🍜'), color=0x83B5E3) embed.set_image(url ='https://www.theflavorbender.com/wp-content/uploads/2019/01/Easy-Chicken-Ramen-Featured-500x375.jpg') else: embed = discord.Embed(title=(f'a bowel of ramen has been given!'), description=('{|__|}\n( • . •)\n/ >🍜'), color=0x83B5E3) embed.set_image(url ='https://www.theflavorbender.com/wp-content/uploads/2019/01/Easy-Chicken-Ramen-Featured-500x375.jpg') await ctx.send(embed=embed) if arg != 'ramen' or 'prawn' or 'lumpia'or 'bubble-tea' or 'fish' or 'prawn' or 'iced-coffee' or 'americano' or 'latte' or 'ice-cream' or 'cheescake' or 'fast-food-meal' or 'burger' or 'fries' or 'ramen':
1 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
您可以使用一个if/elif链,以便从第一个匹配项开始计算:
if arg == 'lumpia':
# do something
elif arg == 'ramen':
# do something
else:
# general case
添加回答
举报
0/150
提交
取消