Reputation: 163
I'm trying the bot to send a message to every server's system channel, but it always ends up sending it to the top channel on a server. Here's my code so far:
@commands.command()
async def broadcast(self, ctx, *, text):
for server in self.client.guilds:
for system_channel in server.text_channels:
try:
await system_channel.send(text)
except Exception:
continue
else: break
Edit: Thank you to TheUntraceable! Here is a working version of it:
@commands.command()
async def broadcast(self, ctx, *, text):
for guild in self.client.guilds:
try:
await guild.system_channel.send(text)
except Exception:
continue
Upvotes: 0
Views: 77
Reputation: 81
You can use the System Channel attribute that a discord.Guild
has
Upvotes: 1
Reputation: 67
The for loop iterate the first channel, send the message and break
at the end stops the loop, thats because the message only sends in the first channel
@commands.command()
async def broadcast(self, ctx, *, text):
for server in self.client.guilds:
for system_channel in server.text_channels:
try:
await system_channel.send(text)
except:
pass
Upvotes: 0