【问题标题】:Why cant I change a message to an Int in Discord.py?为什么我不能在 Discord.py 中将消息更改为 Int?
【发布时间】:2022-01-11 09:43:37
【问题描述】:

我无法在 Discord.py 中将消息更改为 Int。 这是代码。

@bot.command()
async def triv(message):
    v = randint(1,3)
    def check(m):
        return m.author == message.author and m.channel == message.channel
    if int(v) == int(1):
        mn = randint(1, 15)
        mn1 = randint(1, 10)
        mz = mn * mn1
        membed = discord.Embed(
            title="Here's The Question", 
            description=str(mn) + " * " + str(mn1) + '''
Type Your Answer Below.. ''',
            url=None,
            color=discord.Color.blue())
        await message.send(embed=membed)
        gt = await bot.wait_for('message', check=check)
        if int(gt) == int(mz):
            await message.send('''Its Right!!''')
        else:
            await message.send('''Its Wrong... The Answer Was `''' + str(mz) + '''`''')

这是错误信息:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Message'

【问题讨论】:

    标签: python integer discord.py message


    【解决方案1】:

    根据您的代码,gt 是一个 discord.Message 对象。您必须使用gt.content 来获取用户所说的内容。请查看下面修改后的代码部分。

    gt = await bot.wait_for('message', check=check)
    if int(gt.content) == int(mz):
        await message.send('''Its Right!!''')
    else:
        await message.send('''Its Wrong... The Answer Was `''' + str(mz) + '''`''')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 2013-09-22
      相关资源
      最近更新 更多