I'm attempting to create a new Discord bot, and an issue occurs when trying to create a message that is announced to all Discord Servers the bot is currently in.
I have attempted to solve the problem to no avail, this includes looking it up, reading documentation, and of course trying new code.
import discord
import asyncio
from discord.ext import commands
from discord.ext.commands import Bot
TOKEN = [REDACTED]
# client = discord.Client()
client = Bot("!")
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
@client.command(pass_context=True)
async def broadcast(ctx, *, msg):
for server in bot.guilds:
for channel in server.channels:
try:
await channel.send(msg)
except Exception:
continue
else:
break
I expect the program to send my message to all servers the bot is currently in.
Ex: !hello Hi there, this is an announcement!
Should trigger the message following !hello to be broadcasted on every server there is.
EDIT: After some help, I'm still having an issue! The error now is that nothing appears even after doing the command, and if I do it again, it comes up with an error: "Command broadcast is already registered."