【问题标题】:Discord ping vs plaintext, and how to respond to pings with my botDiscord ping 与纯文本,以及如何使用我的机器人响应 ping
【发布时间】:2021-06-16 06:06:21
【问题描述】:

我正在使用 discord.py 创建一个不和谐机器人,它会在 ping 某些用户或角色时做出响应,但我遇到了问题:

在我的代码中,我有以下内容:if message.content == "@league": await message.channel.send("???")

当没有人担任联赛角色时,文本不会突出显示,机器人正常运行。

但是,当我为自己指定角色时,文本显示为突出显示,并且机器人不起作用。

有没有办法使用 discord.py 检查 ping?提前感谢您的帮助

【问题讨论】:

  • 检查message.role_mentions属性

标签: python discord discord.py


【解决方案1】:

您可以做的是获取角色 ID,然后当任何人在消息中拥有角色 ID 时,它会做出响应。 ping 角色算作说 ID。这也适用于用户 ID,因此如果这实际上是您正在 ping 的用户,您也可以只交换使用用户 ID。这是一个例子。

@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)

这应该可以,如果有任何问题,请发表评论。

【讨论】:

    猜你喜欢
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 2020-12-10
    • 1970-01-01
    • 2021-10-23
    • 2021-06-20
    • 2011-06-26
    相关资源
    最近更新 更多