Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending messages in the on_ready? Python discord bot

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 ')
like image 927
Sébastien Avatar asked Jan 26 '20 04:01

Sébastien


1 Answers

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.

like image 116
Erty Seidohl Avatar answered Oct 20 '22 10:10

Erty Seidohl