python - 如何让我的 Discord.py 机器人从与我的主代码位于同一文件夹中的 .txt 文件中随机选择“行”?
问题描述
我正在制作一个整体有趣的机器人,我希望它选择一种已写入 .txt 文件的随机颜色。请在此平台或 Discord 上提供帮助。我的 Discord 用户名是:RelaxedNerd#3072。
解决方案
将它们设置为变量并像这样导入随机会更容易
import random
@client.command()
async def color(ctx):
responses = ['red',
'blue',
'green',
'purple',
'Add more',]
await ctx.send(f'Color: {random.choice(responses)}')
推荐阅读
- django - 在 ModelAdmin 的 ModelForm 中使用 LabelWidget 时,“list”对象没有属性“select_related”错误 [已解决]
- c - 如何修复函数及其声明的“冲突类型”?
- hibernate - 考虑到超类,如何创建hibernate hbm.xml?
- python - 如果有两个具有相同键的不同值,如何更改数据框单元格中的值
- django - Django:我应该在 Django 中使用受保护的方法 _meta 吗?
- javascript - 将选定的菜单选项移动到第一个位置
- elasticsearch - 当我尝试运行 systemctl restart logstash 时,我在 logstash 中收到警告日志错误
- exist-db - Returning xml content on a client API request in eXist-db
- javascript - 堆叠区域系列在行系列的顶部
- php - 在 Laravel 5.8 中删除子类别