繁体   English   中英

Discord.py Killswitch

[英]Discord.py Killswitch

我在 discord.py 上的 killswitch 似乎没有工作,我也不清楚为什么。 有人可以指出我犯的任何错误吗? 谢谢你。

@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()

看起来代码很好,请您再试一次,但不要使用.logout() ,而是使用close() 另外,我建议将其设为仅所有者命令。

如果您将logout更改为close()它应该可以正常工作

如果上述答案不起作用,您可以通过执行exit()quit()退出 python 程序

确保检查它是否是机器人所有者,所以只有你可以关闭它。

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")

您可以使用 if 语句,例如 if allowed == True:在开始时声明 allowed = True ,当该语句运行时将其设置为 false ,您可以使用另一条语句将其重置为 True 并使其再次工作。还放if 语句中的所有命令,否则它将不起作用。可能不是最好或最有效的,但它至少对我来说有效。这是一个例子:

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")

有一个基本示例,所有要禁用的命令都在那里。任何你不想受到影响的东西都放在外面。如果一切都失败了就使用,也不容易受到语法更改的影响,因为它是一个 python 函数(如果语句)不是discors.py 的一部分

这应该可以工作,因为我已经在我的机器人中使用它几个月了。

import discord

client = discord.Client()
admins = [youridhere]

@client.event
async def on_ready():
    print (f'{client.user} has connected to Discord!')

if message.content.startswith("g!shutdown"):
      if message.author.id in admins:
        await message.channel.send("Bot is turning off...")
        await client.close()
      else:
        await message.channel.send("You do not have permission to use this command!")

client.login("token_here")

更容易的是:

@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()

类似的东西

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM