Demotry
Demotry

Reputation: 909

Python send message to multiple channels

Hello i want to send a message to multiple channels using channel id's from any server.

I used below code its working fine for a single channel.

@bot.command(pass_context=True)
async def ping(ctx):
    channel = bot.get_channel("1234567890")
    await bot.send_message(channel, "Pong")

But when i try to add multiple channel id's i getting error TypeError: get_channel() takes 2 positional arguments but 3 were given when i use like below.

channel = bot.get_channel("1234567890", "234567890")

Upvotes: 0

Views: 1227

Answers (1)

Benjin
Benjin

Reputation: 3497

get_channel takes a single argument. You need to loop over all the IDs and send a message to each individually.

@bot.command(pass_context=True)
async def ping(ctx):
    channels_to_send = ["1234567890", "234567890"]
    for channel_id in channels_to_send:
        channel = bot.get_channel(channel_id)
        await bot.send_message(channel, "Pong")

Upvotes: 1

Related Questions