简体   繁体   English

Discord ping 与纯文本,以及如何使用我的机器人响应 ping

[英]Discord ping vs plaintext, and how to respond to pings with my bot

I am creating a discord bot using discord.py that responds when certain users or roles are pinged, and I have run into an issue:我正在使用 discord.py 创建一个 discord 机器人,当某些用户或角色被 ping 时会做出响应,我遇到了一个问题:

In my code I have the following: if message.content == "@league": await message.channel.send("???")在我的代码中,我有以下内容: if message.content == "@league": await message.channel.send("???")

When no one has the league role, the text doesn't appear as highlighted, and the bot functions normally.当没有人担任联赛角色时,文本不会突出显示,机器人正常运行。

当没有人担任联赛角色时,机器人正常工作

However, when I give myself the role, the text appears as highlighted, and the bot doesn't work.但是,当我给自己这个角色时,文本显示为突出显示,并且机器人不起作用。

当用户具有联盟角色时,机器人无法按预期工作

Is there a way to check for pings using discord.py?有没有办法使用 discord.py 检查 ping? Thanks in advance for the help在此先感谢您的帮助

What you could do is get the role ID, and then when anyone has the role ID in a message it responds.您可以做的是获取角色 ID,然后当任何人在消息中具有角色 ID 时,它会做出响应。 Pinging the role counts as saying the ID. ping 角色算作说 ID。 This also works with user ID's so if that's actually a user you're pinging, you can also just swap use the user ID.这也适用于用户 ID,因此如果这实际上是您正在 ping 的用户,您也可以只交换使用用户 ID。 Here's an example.这是一个例子。

@client.listen()
async def on_message(role):
    # add your id instead of the one provided.
    if "<@766730658235154439>" in message.lower.content():
        await ctx.send("???")
        await client.process_commands(role)

This should work, please comment if there is any issues.这应该有效,如果有任何问题,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM