Discord.py: Message on Startup?

Created on 25 May 2017  Â·  6Comments  Â·  Source: Rapptz/discord.py

Is it possible for my bot to send a message to my channel when it is started up?

Right now, I'm using:

@bot.group(pass_context=True)
async def casey(ctx):

if ctx.invoked_subcommand is None:
    await bot.say("Hi, I am a bot!".format(ctx))`

That works fine for prompting a response, but after messing around with it, I can't figure out to get my bot to send a message without being prompted.

All 6 comments

You can use discord.on_ready.

Here's an example:

@bot.event
async def on_ready():
    server = client.get_server("server id")
    await bot.send_message(server.get_channel("channel id"), "Message content")

Thanks!

Unfortunately, I'm getting this error:

AttributeError: module 'discord' has no attribute 'get_server'

You'd have to use the client, so bot.get_server in your case (since the
discord module has no function called get_server). You can also bypass
server.get_channel by using bot.get_channel.

On Thu, May 25, 2017, 07:09 Connor notifications@github.com wrote:

Thanks!

Unfortunately, I'm getting this error:

AttributeError: module 'discord' has no attribute 'get_server'

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Rapptz/discord.py/issues/578#issuecomment-303923896,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKMKqN-kHBrRU4jWcBUYRrh5n8-BKzlJks5r9Qz9gaJpZM4Nl0AH
.

That worked perfectly. Thank you!

I would like to bump this issue back up to life with the 1.0 rewrite.
I can't for the life of me get a message to send once the bot has loaded.

Please don't necrobump issues.
For help using the library, you should join either the official discord.py server or the Discord API server, as the README also links.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adhoc92 picture adhoc92  Â·  3Comments

Be4Vision picture Be4Vision  Â·  3Comments

Yolotroll101 picture Yolotroll101  Â·  3Comments

superloach picture superloach  Â·  3Comments

Spyder-exe picture Spyder-exe  Â·  3Comments