【问题标题】:Discord.py looping messages up to infinityDiscord.py 将消息循环到无穷大
【发布时间】:2021-11-17 10:18:52
【问题描述】:
@client.event
async def on_message(message):
    if message.author == client:
        return
    if message.channel.id == 885569828436447254:
        await message.channel.send(bgmi)
        await message.channel.send(news)

我只是想为特定频道中的每条消息ping 存储在变量bgmi 中的角色,它可以工作! 但问题是每次收到消息时,机器人都会一次又一次地发送消息,直到机器人停止。请帮我配置它,让它只发送一次消息。

【问题讨论】:

  • 嘿,客户端只是一个类,使客户端成为 client.user ,所以它不会重复相同的消息

标签: discord discord.py


【解决方案1】:
@client.event
async def on_message(message):
    if message.guild is None or message.author == message.guild.me:
        return
    if message.channel.id == 885569828436447254:
        await message.channel.send(bgmi)
        await message.channel.send(news)

您应该使用Guild.me。在公会中,message.author 是 Discord 类型 Member,而 client 只是用于管理 discord 之间通信的 python 类型。你真正想要的是Guild.me

仅当消息在不和谐服务器中发送时才有效,对于私人频道,您需要这样做

【讨论】:

    【解决方案2】:

    if message.author == client: 替换为if message.author == client.user:

    【讨论】:

      猜你喜欢
      • 2023-02-07
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 2014-02-14
      • 2020-10-01
      • 2014-10-30
      • 1970-01-01
      • 2017-03-08
      相关资源
      最近更新 更多