2024-09-29 19:32:10 发布
网友
我们的bot中有一个globalchat函数,我们不希望人们通过它提及其他人或所有人,因此我们在消息中禁用了“@”符号,但现在如果您键入“@Hello World!”,它将返回,您的消息将不会发送
if "@" in message.content: return
如何检查该消息中是否有提及?留言,说什么
不和谐的提及并不是这样处理的,一个原始的用户提及看起来像这样<@{id_here}>,一个缺口提及看起来像这样<@!{id_here}>
<@{id_here}>
<@!{id_here}>
您可以创建一个简单的正则表达式,但是Message对象已经具有mentions属性,该属性返回discord.User/discord.Member实例列表:
Message
mentions
discord.User
discord.Member
if message.mentions: # If the list is not empty return
不和谐的提及并不是这样处理的,一个原始的用户提及看起来像这样
<@{id_here}>
,一个缺口提及看起来像这样<@!{id_here}>
您可以创建一个简单的正则表达式,但是
Message
对象已经具有mentions
属性,该属性返回discord.User
/discord.Member
实例列表:参考资料:
相关问题 更多 >
编程相关推荐