【问题标题】:Discord Bot TypeErrorDiscord Bot 类型错误
【发布时间】:2018-05-02 06:22:57
【问题描述】:

我正在尝试制作一个不和谐的机器人游戏,其中玩家说“击中”并且怪物受到随机数量的伤害。怪物受到一定程度的伤害后,它们会死亡并出现一个新的怪物。 但是,当我在 discord 中输入“hit”时,我收到一个错误提示

TypeError: send_message() takes from 2 to 3 positional arguments but 7 were given

这是我的代码:

@client.command(pass_context=True)
async def hit (ctx):
    global HP
    damage = random.randrange(50,500)
    HP -= damage
    if HP > 0 :
        await client.say('The monster took', damage, 'damage and has', HP, 'health left')
    else :
        await client.say('The monster has died! Another one approaches...')
        HP = random.randrange(600,1000)

请有人告诉我出了什么问题以及如何解决它。谢谢!

【问题讨论】:

    标签: python-3.x discord


    【解决方案1】:

    将字符串传递给client.say() 时,您没有正确创建/连接字符串

    client.say('The monster took', damage, 'damage and has', HP, 'health left')
    

    这里每有一个逗号,就被当作一个新参数传递给函数。

    您需要创建字符串并将其作为一个变量传递:

    client.say('The monster took ' + damage + ' damage and has ' + HP + ' health left')
    

    注意这里使用+ 而不是, 来加入字符串。

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 2017-11-05
      • 2019-11-10
      • 2021-07-15
      • 2019-02-03
      • 2018-03-12
      • 2018-03-04
      • 2021-04-12
      相关资源
      最近更新 更多