【问题标题】:Discord.py send message when another user posts a messageDiscord.py 在其他用户发布消息时发送消息
【发布时间】:2021-07-18 11:01:55
【问题描述】:

我正在 discord.py 中创建一个机器人,并希望我的机器人在 Webhook 在特定通道中发送消息时 ping 角色。有没有办法做到这一点?现在我只有频道 ID,我很确定它是一个客户端事件

@client.event
async def pingrole():
  channel = client.get_channel("channel id")

【问题讨论】:

  • 您必须使用on_message 事件并检查消息
  • 我忘了说,它是一个 Webhook,所以我希望机器人在 Webhook 发布内容时 ping 通
  • 您仍然需要使用on_message 事件。
  • 你可以像@Dominik所说的那样使用on_messageget role by id,然后使用.mention提及它。示例:role = guild.get_role(id)role.mention,然后您可以将其作为消息发送。

标签: discord discord.py


【解决方案1】:
async def on_message(message):
    if message.author.id == webhook.id:
        await ctx.send(role.mention)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-08
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 2020-11-10
    • 2020-10-31
    相关资源
    最近更新 更多