为什么函数会报错?不和谐.py

时间:2021-06-05 19:39:24

标签: python function discord discord.py

def test():
    await message.author.send('ehy')

@bot.event
async def on_message(message):
        if message.author.id == 2980828228298:
            test()

我不明白为什么这个简单的功能不起作用。错误是“等待”。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

我不是discord.py大师,实际上我对此一无所知。虽然我知道为了使用 await 它必须在 async 函数内。使用您提供的代码,我想您可以在 test() 函数中返回一个字符串。

def test():
    return 'ehy'

@bot.event
async def on_message(message):
        if message.author.id == 2980828228298:
            await message.author.send(test())