【问题标题】:How to make random output command in discord [Python] [duplicate]如何在不和谐 [Python] [重复] 中制作随机输出命令
【发布时间】:2019-02-20 04:24:08
【问题描述】:
@bot.command(pass_context=True)
async def coinflip(ctx):
    variable = [
        "head",
        "tail",]
    await bot.say(ctx.message.channel, "{}".format(random.choice(variable)))

Python 说“随机”没有定义,如何解决这个问题

【问题讨论】:

  • 导入模块。

标签: python bots discord discord.py


【解决方案1】:

您必须导入 random 模块。

import random

...

@bot.command(pass_context=True)
async def coinflip(ctx):
    variable = [
        "head",
        "tail",]
    await bot.say(ctx.message.channel, "{}".format(random.choice(variable)))

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 2017-04-29
    • 2018-07-01
    • 2021-04-19
    • 1970-01-01
    • 2021-10-05
    • 2021-06-02
    • 1970-01-01
    • 2020-10-09
    相关资源
    最近更新 更多