如何从 Discord 消息中的提及中获取角色 ID?

How to get role id from mention in a Discord message?

我正在为一个 discord 机器人做一个项目,并且已经到了我卡住的地步(python 和 discord API 的初学者)。我几乎想要做的是让函数测试消息以检查其中是否提到了角色。

这是我坚持的部分的 sudo 示例:

def test(message):
  if @role (given role) in message:
     then do this

感谢任何帮助,我已经完成了几乎所有的工作,只是这部分我没有任何线索。

也许你可以这样做,只是为了检查 roleid,使用命令

@bot.command(aliases=['cri'])
async def checkroleid(ctx, role: discord.Role):
    await ctx.send(f"Here the role id `{role.id}`")