Sending messages in the on_ready? Python discord bot
28,399
You don't have a channel selected to send a message to. First, you need to select a channel, then you can send a message to that channel.
channel = client.get_channel(12324234183172)
await channel.send('hello')
You can get the channel ID by iterating over the list of channels in the connected server:
text_channel_list = []
for server in Client.servers:
for channel in server.channels:
if channel.type == 'Text':
text_channel_list.append(channel)
From How to get all text channels using discord.py?
From How do I send a message to a specific channel? in the discord python FAQ.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on July 19, 2022Comments
-
Admin almost 2 years
I want my bot to send a message when going online in the on_ready event. The line work in (on_message) but I haven't been able to make it send something in the (on_ready)
@client.event async def on_ready(): print('We have logged in as {0.user}'.format(client)) await message.channel.send('The bot is online ')