Q
Q
Quaasaar2020-05-10 22:02:56
Python
Quaasaar, 2020-05-10 22:02:56

Discord.py how to make the BOT send messages to all channels at once?

I need the bot to send out messages to all channels on the server after writing the command. For example, some kind of announcement. As I understand it, you need to make a cycle in which you need to determine the channel IDs, and then send a message to them. But how to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Gafarchik, 2020-05-10
@Gafarchik

@bot.command(pass_context=True)
async def test(ctx, *, msg):
    for server in bot.servers:
        for channel in server.channels:
            try:
                await bot.send_message(channel, msg)
            except Exception:
                continue
            else:
                break

try something like this.
This code iterates through all the channels of the server until it finds one that can send a message

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question