SecurityQuy
SecurityQuy

Reputation: 15

Python - Discord bot on ready send message to channel

I have problem creating simple python script which sends message to default channel when executed from terminal.

import discord

@bot.event
async def on_ready(ctx):
    print('Online')
    await ctx.send('Message sent!')


bot.run('MYTOKEN')

with this example I keep getting "ctx" is not defined

Upvotes: 0

Views: 4011

Answers (1)

Omar Nasr
Omar Nasr

Reputation: 406

The issue here is that the on_ready event should not receive any parameters. See the Minimal Bot documentation here and the on_ready documentation in the Event Reference here. If you want to send a message when the bot connects. You must first get the channel object and then use the send method. You can find an example of getting a channel and sending a message in the FAQ section of the docs here

Upvotes: 1

Related Questions