首页 > 解决方案 > 为什么函数会出错?不和谐.py

问题描述

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

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

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

标签: pythonfunctiondiscorddiscord.py

解决方案


我不是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())

推荐阅读