Konrad Dybcio
Konrad Dybcio

Reputation: 21

How do I send a message to ALL text channels with Discord.py?

I want to send a message (let's say "Hello") to every single channel on my server. I expect it to lag a little bit, since (afaik) there's a limitation of ~5 messages/3 seconds, but still it would be easier to wait than to manually send the message to each channel.

Cannot really figure out if it's even possible to do this.

Upvotes: 2

Views: 5347

Answers (2)

JSHTMLEXEPYTHON
JSHTMLEXEPYTHON

Reputation: 1

It is possible. If you are using "bot" instead of "client", you can try this code:

@bot.command()
async def send_all(message, member):
channels = bot.get_all_channels()
    for channel in channels()
        if channel.permissions_for(member):
             await bot.send_message(channel, message)

This might not work, but you shold try. I hope I helped you :)

Upvotes: 0

TwistedSim
TwistedSim

Reputation: 2030

You con use a combination of the coroutine await client.send_message(channel, message) and client.get_all_channels(). YOu can also check if you have the permission to send a message to the channel with Channel.permissions_for(member). If you need more information, take a look the the API reference.

It may look something like:

async def send_all(message, member):
    for channel in client.get_all_channels()
        if channel.permissions_for(member):
             await client.send_message(channel, message)

Upvotes: 2

Related Questions