How to send a message on the bot startup to every server it is in?
First, to answer your question about default_channel
: Since about June 2017, Discord no longer defines a "default" channel, and as such, the default_channel
element of a server is usually set to None
.
Next, by saying discord.Server.default_channel
, you're asking for an element of the class definition, not an actual channel. To get an actual channel, you need an instance of a server.
Now, to answer the original question, which is to send a message to every channel, you need to find a channel in the server that you can actually post messages in:
python
@bot.event
async def on_ready():
for server in bot.servers:
# Spin through every server
for channel in server.channels:
# Channels on the server
if channel.permissions_for(server.me).send_messages:
await bot.send_message(channel, "...")
# So that we don't send to every channel:
break