Discord.py-无限循环问题

时间:2020-05-23 01:08:03

标签: python discord discord.py

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

当前结果:它循环遍历并一次又一次地发布到所有渠道。还要在消息来源的通道中发布。

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

1 个答案:

答案 0 :(得分: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))