How do I send a message to every channel in a discord server simultaneously?
I used this code from another post but I receive no response when running the command.
@client.command(pass_context=True)
async def broadcast(ctx, *, msg):
for guild in bot.guilds:
for channel in guild.channels:
try:
await bot.send_message(channel, msg)
except Exception:
continue
else:
break
You've used client
in some places and bot
in some other places, more over this code isn't very efficient as it's not required to iterate through the guilds when you're calling it from only one server, that would cause spam in multiple servers. I've also noticed you're using functions from an older version of discord.py
. Try using this instead:
@client.command()
async def broadcast(ctx, *, msg):
for channel in ctx.guild.text_channels:
try:
await channel.send(msg)
except:
continue
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.