【问题标题】:Discord.py - Infinite Looping IssueDiscord.py - 无限循环问题
【发布时间】:2020-09-09 22:51:20
【问题描述】:

我的目标:遍历不和谐服务器频道列表并中继消息(不包括消息来自的服务器)

当前结果:它一遍又一遍地循环播放并发布到所有频道。也在消息来源的频道中发帖。

class MyClient(discord.Client):
    async def on_ready(self):
        print('{0} is in the building!'.format(self.user))
        print(self.user.id)
        print('------')

    async def on_message(self, message):

        # relay cod messages
        if message.channel.id in cod_chanlist:
            for chan in cod_chanlist:
                if message.channel.id == chan:
                    pass
                else:
                    game_channel = client.get_channel(chan)
                    await game_channel.send('{0.author}: {0.content}'.format(message))

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您可以检查该消息不是由机器人发送的,并检查原始消息的公会:

    async def on_message(self, message):
        if message.author.bot:
            return
        # relay cod messages
        if message.channel.id in cod_chanlist:
            for chan in cod_chanlist:
                game_channel = client.get_channel(chan)
                if game_channel.guild != message.guild:
                    await game_channel.send('{0.author}: {0.content}'.format(message))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-03
      • 2021-09-02
      • 2021-09-11
      • 2018-09-24
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多