python - 如何根据嵌入的数组更改嵌入页脚?
问题描述
我正在尝试制作一个角色扮演机器人命令,其中用户标记另一个人,然后机器人必须说些什么,然后它出现一个随机图像,页脚必须说哪个是图片中的角色,我什至想这样做更多的数组,每个字符一个,但我不知道我是否让自己复杂化了很多,即使我所做的没有工作,我也不知道为什么。
#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)
解决方案
我稍微更改了您的代码,对我来说它工作正常,如下所示:
@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)
编辑: 功能在数组中添加了多个 gif。很确定这不是最好的方法,但它确实有效。
@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)
推荐阅读
- java - 如何同时重新加载所有片段
- postgis - 如何获取我的geom中的点与入口点经度和纬度之间的距离
- html - 如何使用 R 触发文件下载
- botframework - Bot Framework 渲染选项更改格式
- css - Safari 12 中对象位置的 CSS 动画
- c# - console.write("\r") 不在服务器上的同一行中显示元素
- jquery - 可见性“动画”,但 SCSS 中的反向效果有延迟
- java - 带有逗号分隔的 currentFunctionPath 列表的 JDBC DB2 URL
- android - 在布局的中心|底部添加一个静态按钮
- azure - 了解 Test-AzureRmPrivateIPAddressAvailability 。应用程序网关私有 IP 被列为可用