有没有办法寻找角色ping? (discord.py)

Posted

技术标签:

【中文标题】有没有办法寻找角色ping? (discord.py)【英文标题】:Is there a way to look for a role ping? (discord.py) 【发布时间】:2021-08-10 21:07:27 【问题描述】:

标题说明了一切。 我试着寻找 id:

if "845314564555931660" in message.content: 我尝试在整数中查找 id: if 845314564555931660 in message.content: 整数会识别它,但会出错,因为它正在寻找 str 中的 int。 我尝试将 id 转换为 ping: if <@845314564555931660> in message.content:

我尝试单独使用 ping:

if "@Sugarcane" in message.content:

没有人可以检测到该消息。

【问题讨论】:

【参考方案1】:

您可以使用discord.Message.role_mentionsdiscord.Message.raw_role_mentions 属性。

.role_mentions 返回消息中提到的 discord.Role 对象的列表 .raw_role_mentions 以整数形式返回角色 ID 列表。

【讨论】:

以上是关于有没有办法寻找角色ping? (discord.py)的主要内容,如果未能解决你的问题,请参考以下文章