如何在discord.py中检查邮件是否包含提及?

2024-09-29 19:32:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我们的bot中有一个globalchat函数,我们不希望人们通过它提及其他人或所有人,因此我们在消息中禁用了“@”符号,但现在如果您键入“@Hello World!”,它将返回,您的消息将不会发送

                if "@" in message.content:
                    return

如何检查该消息中是否有提及?留言,说什么


Tags: 函数in消息messagehelloworld键入return
1条回答
网友
1楼 · 发布于 2024-09-29 19:32:10

不和谐的提及并不是这样处理的,一个原始的用户提及看起来像这样<@{id_here}>,一个缺口提及看起来像这样<@!{id_here}>

您可以创建一个简单的正则表达式,但是Message对象已经具有mentions属性,该属性返回discord.User/discord.Member实例列表:

if message.mentions: # If the list is not empty
    return

参考资料:

相关问题 更多 >

    热门问题