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