Python discord bot send to multiple channels problem

Viewed 623

I've got a problem with sending a message to multiple channels. When I do the command, it sends just to the channel I wrote from for 8 times. Here is my code:

import discord
import config
client = discord.Client()


@client.event
async def on_message(message):
    
    id = client.get_guild(config.ID)
    channels = [647074685535649802, 636901028478058497, 690272147050070158, 694196995887202375, 690276595578962177, 654662320735387648, 650381379892412426, 641704849196711976]
    valid_users = ["Resadesker#1103"]
    
    if str(message.author) in valid_users:
            for channelo in channels:
                if message.content.find("$spam") != -1:
                    print(channelo)
                    channel = client.get_channel(channelo)
                    print(channel)
                    await message.channel.send(message.content[message.content.find(' '):]) 
client.run(config.TOKEN)
1 Answers

It looks like you are sending your response to the channel from message, try this:

@client.event
async def on_message(message):

    id = client.get_guild(config.ID)
    channels = [
        647074685535649802, 
        636901028478058497, 
        690272147050070158, 
        694196995887202375, 
        690276595578962177, 
        654662320735387648, 
        650381379892412426, 
        641704849196711976,
    ]
    valid_users = ["Resadesker#1103"]

    if str(message.author) in valid_users:
       for channelo in channels:
            if message.content.find("$spam") != -1:
                print(channelo)
                channel = client.get_channel(channelo)
                print(channel)
                await channel.send(message.content[message.content.find(' '):]) 
Related