I'm trying to make a roleplay bot command where the user tags another person and then the bot has to say something and then it appears a random image and the footer must say which is the character from the picture, I want to do even with more arrays, one for each character maybe but I don´t know if I am complicating my self a lot, and even though what I have done is not working and I don't know why.
#Example for StackOverflow
@bot.command()
async def roleplaying (ctx, user:discord.User):
nyan_cat= ["https://1.bp.blogspot.com/-XBOvQhJ4e3E/YINVEJxvRyI/AAAAAAAAATo/S-PlEpwNLzs250tmpWEzkmiLt_Fbeu5UACLcBGAsYHQ/s476/Nyan%2Bcat.gif"]
pikachu = ["https://c.tenor.com/-VYWaSmWx2QAAAAC/thunderbolt-pikachu.gif"]
random_image= random.choice([nyan_cat,pikachu])
avc = discord.Embed(
title= "",
description= f"**{ctx.message.author.name}** wants **{user.name}** to watch the picture ❤️",
colour=0x0101df
)
if random_image == nyan_cat:
avc.set_image(url=random_image)
avc.set_footer(text= "Character: Nyan Cat.")
await ctx.send(embed=avc)
elif random_image == pikachu:
avc.set_image(url=random_image)
avc.set_footer(text= "Character: Pikachu.")
await ctx.send(embed=avc)
I changed your code a little and for me it's working fine like this:
@bot.command()
async def roleplaying (ctx, user:discord.User):
nyan_cat= "https://1.bp.blogspot.com/-XBOvQhJ4e3E/YINVEJxvRyI/AAAAAAAAATo/S-PlEpwNLzs250tmpWEzkmiLt_Fbeu5UACLcBGAsYHQ/s476/Nyan%2Bcat.gif"
pikachu = "https://c.tenor.com/-VYWaSmWx2QAAAAC/thunderbolt-pikachu.gif"
random_image= random.choice([nyan_cat, pikachu])
avc = discord.Embed(title= "",
description= f"**{ctx.message.author.name}** wants **{user.name}** to watch the picture ❤️",
colour=0x0101df)
if random_image == nyan_cat:
avc.set_image(url=random_image)
avc.set_footer(text= "Character: Nyan Cat.")
await ctx.send(embed=avc)
elif random_image == pikachu:
avc.set_image(url=random_image)
avc.set_footer(text= "Character: Pikachu.")
await ctx.send(embed=avc)
EDIT: Feature added multiple gifs in array. Pretty sure it's not the best way to do it, but it works.
@bot.command(name='roleplaying')
async def roleplaying(ctx, user:discord.User):
nyan_cat= [ "https://1.bp.blogspot.com/-XBOvQhJ4e3E/YINVEJxvRyI/AAAAAAAAATo/S-PlEpwNLzs250tmpWEzkmiLt_Fbeu5UACLcBGAsYHQ/s476/Nyan%2Bcat.gif", "https://icegif.com/wp-content/uploads/nyan-cat-icegif-5.gif" ]
pikachu = [ "https://c.tenor.com/-VYWaSmWx2QAAAAC/thunderbolt-pikachu.gif", "https://c.tenor.com/P9pPZ1prRCMAAAAd/pokemon-pikachu.gif" ]
random_char = random.choice(['nyan_cat', 'pikachu'])
if random_char == 'nyan_cat':
random_image = random.choice(nyan_cat)
elif random_char == 'pikachu':
random_image = random.choice(pikachu)
avc = discord.Embed(title= "",
description= f"**{ctx.message.author.name}** wants **{user.name}** to watch the picture ❤️",
colour=0x0101df)
if random_char == 'nyan_cat':
avc.set_image(url=random_image)
avc.set_footer(text= "Character: Nyan Cat.")
await ctx.send(embed=avc)
elif random_char == 'pikachu':
avc.set_image(url=random_image)
avc.set_footer(text= "Character: Pikachu.")
await ctx.send(embed=avc)