在 on_message 中使用 def 函数发送消息

时间:2021-01-20 21:02:00

标签: python function discord.py python-asyncio

如何在图片中提到的 () 中发送消息? Image

代码:

@bot.event
async def on_message(message):
    if message.author == client.user:
        return
    if "!" in message.content:
    
        await message.channel.send("selam naber...")
        
        zzz1=await message.channel.send("fai.")
        zzz2=await message.channel.send("hit...")
        
       def a():
            zzz2
        a()

这是一个理解的例子 (当你像图片中那样做时不会发生这种情况。)

对不起我的英语

1 个答案:

答案 0 :(得分:2)

a 函数应该是一个协程,因为您在其中使用了 await 关键字

async def a():
    await message.channel.send("something")

要调用它,您还需要等待它

await a()