Discord.py Killswitch

Viewed 611

My killswitch on discord.py does not seem to be working and I haven't the foggiest as to why. Could someone please point out any errors that I have made? Thank you.

@client.command(aliases=["shut","shutdown","quit","stop_that","stahp", "kill"])
async def stop(ctx):
   await ctx.send("Attention: I have been murdered.")
   await client.logout()
5 Answers

It seems that the code is fine, try it again but instead of .logout(), use close(). Also I would recommend making it owner-only command.

If the above answers don't work you could quit the python program by doing exit() or quit()

Make sure to check if it's the bot owner, so only you can shut it down.

import discord
from discord.ext import commands

client = commands.Bot(command_prefix="!", owner_id=youridhere) # youridhere is type int

@client.command(aliases=['stopbot'])
@commands.is_owner()
async def logout(ctx):
    await ctx.send(f"I'm going offline {ctx.author.mention}! Bye :wave:!")
    await client.logout()

client.run("YOURTOKENHERE")

You can use a if statement such as if allowed == True: declare allowed = True in the beginning and when that statement runs have it set allow to false, with another statement you can reset it to True and make it work again.Also put all your commands in the if statement or else it won't work.May not be the best or most efficient but it works , atleast for me.Heres a example:

import discord

allowed = True

client.command(aliases=["awaken","start","restart"])
async def start(ctx):
   await ctx.send("Attention: I have been reborn.")
   allowed = True

client.command(aliases=["shut","shutdown","quit","stop_that","stahp", "kill"])
async def stop(ctx): #outside of if statement so it won't be affected
   await ctx.send("Attention: I have been executed.")
   allowed = False

if allowed == True:
   client.command(aliases=["pain","and","suffering"])
   async def speeek(ctx): # in if statement will be affected
      await ctx.send("Attention: I have been suffering all year.")

   client.command(aliases=["ah","ahhhh","oh my gawd"])
   async def SCREEEAM(ctx):
      await ctx.send("AAAAAHHHHHHHH")

There's a basic example all commands that are to be disabled are there.Anything you don't want to be affected place it outside.Use if all else fails, also not vulnerable to syntax changes as its a python function(if statements) not a part of discors.py

Much easier would be:

@client.command()
async def offline(ctx):
    TeamIDS=[id from your bot mates whatever]
    if ctx.author.id in TeamIDS:
        print(f"{ctx.author} hat den Bot ausgemacht.")
        await ctx.send("Bye bye")
        exit()

Something like that

Related