首页 > 解决方案 > 如何让我的 Discord.py 机器人从与我的主代码位于同一文件夹中的 .txt 文件中随机选择“行”?

问题描述

我正在制作一个整体有趣的机器人,我希望它选择一种已写入 .txt 文件的随机颜色。请在此平台或 Discord 上提供帮助。我的 Discord 用户名是:RelaxedNerd#3072。

标签: pythondiscord.py

解决方案


将它们设置为变量并像这样导入随机会更容易

import random

@client.command()
async def color(ctx):
    responses = ['red',
                 'blue',
                 'green',
                 'purple',
                 'Add more',]
    await ctx.send(f'Color: {random.choice(responses)}')

推荐阅读