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 ')
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With