How to stop running discord bot process (python)
Solution 1
- If you add the code that I wrote down there (that only the owner can use) will shut down the already running bots (write /shutdown in discord server or whatever your prefix is).
However, you may need a PC restart after saving the bot with this code.
@client.command()
@commands.is_owner()
async def shutdown(ctx):
await ctx.bot.logout()
- So every time if you want to edit your command, you write /shutdown and edit it, after that, you can start it again.
I hope this works for you and that I could help.
Solution 2
A way to end the entire script your bot is running on is by using the built in python functions exit()
and quit()
both do the same thing.
@bot.command()
@commands.is_owner()
async def shutdown(context):
exit()
by putting @commands.is_owner()
you're making it so that only the owner of the bot can use this command. To invoke this command type /shutdown
in your discord server (replace the /
with whatever your prefix is).
It raises a bunch of errors but overall ends the program so conclusively it may not be the most efficient method but it does the job.
Solution 3
This message really is not discord.py specific and applies to every script which runs indefinetely.
You are running multiple instances of your bot. If you run it in an IDE envoirment, then there should be a stop button somewhere. If you are running it in console, closing the console window will close the bot.
Edit: If you are running it in sublime3 like your tags suggest, every time you want to close your bot, go to "Tools" and then "Cancel Build" (hotkey: CTRL + Break). As soon as you run another instance of your bot, sublime "decouples" the current script in favour of the new one and this method does not work anymore. Then you have to manually go through your running processes (command line or Task Manager) and search for any "Python" processes.
In general I reccomend running the script in the commandline instead as you have more control over it.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
Im new at this discord.py thing. I've just done a discord.py bot, it works ok, but sometimes the bot repeats constantly the command messages. I googled this problem and found out that maybe is for running the script over and over again (like when you save and run after edited or added functions). So I want to stop running the process, just like when I restart windows, the bot is offline (if I run the script after restarting windows, the bot acts normaly). Pls help
If someone needs the code, I can paste it here then.
PD: I made the bot exact as a tutorial...
-
theptrk over 4 yearsYou may need to manually add the
.close()
explained here: github.com/Rapptz/discord.py/issues/2040 -
theptrk over 4 yearsI would be useful if you include the link to the tutorial so its easier to help.
-
BrainDead over 4 yearsThis is your root problem
the bot repeats constantly the command messages
please give more info about it. -
Admin over 4 yearsThe tutorial link: youtube.com/watch?v=DEqrCI1018I
-
Faisal Amin over 2 yearsjust type
exit
in visual studio code output terminal and your bot will be disconnected. Enjoy the day
-
-
Admin over 4 yearsWow thanks. I'll try it. Really appreciate your explanation.
-
Admin over 4 years1 more question. Which is the command to stop the process in the terminal (or command prompt)? Thanks btw
-
ArjixGamer about 3 yearsum, it is recommended to use cogs and then just unload and load the cog, so there is no need to restart the bot just to update a command.
-
Gaming with Akashdeep over 2 yearsit says bot object has no attribute logout