python - 如何将 .random.choice() 函数与 url(特别是 gif)一起使用?
问题描述
我最近创建了一个非常简单的不和谐机器人,它会根据命令给你一个随机的选项引用。我也想做同样的事情,但使用 GIF。格式一样吗?
第一个代码是我的报价机器人编码,第二个是我尝试嵌入 gif,但我不知道如何将 .random.choice() 合并到这个......
@client.command(brief='-positivity', description='will give you a positive quote!')
async def positivity(ctx):
quotes = [#choice1, #choice2, ...., choice#25]
await ctx.send(f'**{random.choice(quotes)}**')
\\
@client.command(brief='-hug', desription="Will give you a warm hug")
async def hug(ctx):
gif = discord.Embed(title = 'A hug has been sent!', description = 'warm, fuzzy and comforting <3', color = 0x83B5E3)
gif.set_image(url = 'https://media.giphy.com/media/fvN5KrNcKKUyX7hNIA/giphy.gif')
await ctx.channel.send(embed=gif)
解决方案
>>> import random
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'gif2'
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'gif2'
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'gif1'
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'url3'
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'gif1'
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'url3'
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'gif2'
>>> random.choice(['gif1', 'gif2', 'url3', 'hello world'])
'hello world'
我猜你可能想做这样的事情:
quotes = ['quote one', 'etc...']
await ctx.send(random.choice(quotes))
推荐阅读
- sbt - 如何将 SBT 的开发版本发布到我的 Artifactory ivy2 存储库?
- blender - 如何在 Blender 中为对象添加凹面区域
- django - 如何在 CBV 的 django 分页中显示页面项目数?
- android - Aws 放大 cli - 缺少 awsconfiguration.json
- sql - 优化带数据时间过长的SQL查询
- python - 此平台不支持.whl
- angular - 在从不同组件调用该变量后返回未定义的布尔变量
- python - 为什么斐波那契函数的性能时间图不平滑?
- javascript - 使用 CoinDesk API 获取比特币价格指数实时数据
- api - Youtube API 刷新令牌错误 400(OAuth2 错误)