首页 > 解决方案 > 如果为假,如何让我的程序跳过“on_message”函数(discord.py重写)

问题描述

我想让我的机器人能够在编写某个命令时标记成员,但我能够做到这一点的唯一方法是使用 on_message 命令,它似乎只是停止我的程序,无论是假还是真,即使它在何时激活真的

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith('m-example'):
        await message.channel.send('<' + '@' + '{}' .format(message.author.id) +'>' + ' example!')

标签: pythondiscorddiscord.py

解决方案


首先,您可以轻松地提及某人,对于此示例,使用message.author.mention,其次我不知道您有什么问题,但现在可能可行:

@client.event
async def on_message(message):
    if message.author.id != bot.user.id: 
        if message.content.startswith('m-example'):
            await message.channel.send(f"{message.author.mention} example!")

推荐阅读