【问题标题】:How do I make my Discord.py bot pick a random "line" from a .txt file in the same folder as my main code?如何让我的 Discord.py 机器人从与我的主代码位于同一文件夹中的 .txt 文件中选择一个随机“行”?
【发布时间】:2020-05-27 09:11:03
【问题描述】:

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

【问题讨论】:

  • 这与discord.py有关吗?
  • 在 StackOverflow 上提出与代码相关的问题...展示你自己的努力
  • 到目前为止你尝试了什么?

标签: python discord.py


【解决方案1】:

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

import random

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

【讨论】:

    猜你喜欢
    • 2022-11-18
    • 2019-12-13
    • 1970-01-01
    • 2021-07-12
    • 2020-10-18
    • 2020-08-09
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    相关资源
    最近更新 更多