Stack Overflow Asked by Amy sdj on November 4, 2021
I’ve created a bot that when commanded with ?give {arg}, will output {arg} has been given!. However, I’ve added some specific foods that will output a different message (eg. ramen will output an image of ramen), but, because it’s still technically an arg, the bot outputs both messages, how do I code it so that if the arg is one of the specific foods, the bot will only output that specific message?
my code currently:
@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':
if member:
username = ctx.message.author.display_name
name = member.display_name
embed = discord.Embed(title=(f'{username} has given (a) {arg} to {name}!'), description='uwu', color=0x83B5E3)
else:
embed = discord.Embed(title=(f'(A) {arg} has been given!'), description='uwu', color=0x83B5E3)
await ctx.send(embed=embed)
You can use an if/elif
chain so that the evaluation starts at the first match:
if arg == 'lumpia':
# do something
elif arg == 'ramen':
# do something
else:
# general case
Answered by Aplet123 on November 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP