Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Discord.py-无限循环问题_Python_Discord_Discord.py - Fatal编程技术网

Python Discord.py-无限循环问题

Python Discord.py-无限循环问题,python,discord,discord.py,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('------')

我的目标是:在不一致的服务器通道列表中循环并转发消息(不包括消息来自的服务器)

目前的结果是:它一次又一次地循环并发布到所有渠道。也在消息来源的频道中发布

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

您可以检查邮件是否不是由机器人发送的,并对照原始邮件的公会进行检查:

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