Reputation: 119
I want to create a command for my discord bot that makes the bot offline for everyone. I want to type that command in any discord server and then the bot just goes offline. This is much easier than going into your files or terminal to press ctrl+c. Is a command like this possible to even make? And if so, can I please know how to add that command? I want to add some admin commands to my bot and this is definitely a great addition to the list. Thanks -
Upvotes: 0
Views: 2888
Reputation: 116
I would suggest choosing a more graceful exit for your bot, which would be using await bot.close()
if you are using master branch of discord.py, it cleanly closes the websocket connection it makes to discord.
@bot.command()
async def shutdown(ctx):
await ctx.send("Shutting down bot!")
await bot.close()
If you are using the stable version, i.e 1.7.3 which is installed when you do pip install discord.py
, you can use await bot.logout()
instead
Unlike master branch's Bot.close, this drops all connections immediately.
@bot.command()
async def shutdown(ctx):
await ctx.send("Shutting down bot!")
await bot.logout()
Upvotes: 1
Reputation: 66
If I'm understanding what you're trying to do here, you can just add a command that exits the bot.py
program by making a call to something like sys.exit()
. This would just terminate the program running the bot, making the bot go offline.
Upvotes: 0