繁体   English   中英

如何让我的 Discord.py 机器人从与我的主代码相同的文件夹中的 .txt 文件中随机选择一条“行”?

[英]How do I make my Discord.py bot pick a random "line" from a .txt file in the same folder as my main code?

我正在制作一个整体有趣的机器人,我希望它选择一种已写入 .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)}')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM