我在下面得到了这个脚本,该脚本将消息发送到所有具有“聊天通道”通道的服务器,但是问题在于它意味着要发送到每个称为“聊天通道”的通道,服务器本身具有该通道所以机器人将其发送到您从我发送过来的服务器中的通道上,这是我不想要的,有什么办法可以解决此问题?
(In short: The bot should send message to all servers that have the bot and a channel called 'Chat-channel' but not send to that server the message was sent from even thought it has a channel called 'Chat-channel')
Chnls=[]
@bot.event
async def on_message(message):
if message.author != bot.user:
for chan in Chnls:
ch=get(bot.get_all_channels(),id=chan)
if ch.name=='Chat-channel' and ch.id in Chnls:
await ch.send(message.content)
答案 0 :(得分:0)
您声明您已经具有要发布到的服务器列表。在每台服务器上,您可以(根据文档:https://discordpy.readthedocs.io/en/latest/api.html#server)调用int
以返回该服务器中所有成员的可迭代对象。用伪代码(即需要修改):
.members
答案 1 :(得分:0)
再次假设您已经拥有频道ID的列表,则可以使用此方法来防止您的漫游器在频道中发送相同的消息
chans=[]
@bot.event
async def on_message(msg):
if msg.channel.name == 'chat-chan' and msg.author.bot == False:
for i in chans:
if i != msg.channel.id:
await bot.send_message(discord.Object(id=i),msg.content)
await bot.process_commands(msg)