不和谐的机器人禁止一个人

时间:2020-10-17 19:00:18

标签: discord.py discord.py-rewrite

有没有一种方法可以禁止某人使用漫游器的命令。基本上是给那个人一个Bot Ban!

Discord.py

2 个答案:

答案 0 :(得分:0)

发出一个ban命令,然后在运行ban命令而不是禁止该人时,您要给他们授予被禁止的角色,因此,每当运行命令时,您都可以检查某人是否具有该角色以及他们是否会执行该命令< / p>

答案 1 :(得分:0)

您只需以您喜欢的任何方式(列表,json,txt文件或任何数据库)简单地存储禁止用户的ID,然后当用户使用命令时,机器人将检查用户ID是否已存储。

您还可以执行将用户ID添加到列表的命令,但是请记住,新ID不会永远存储,换句话说,如果您关闭了漫游器,则数据将消失。

简单示例:

#stored ids 
BANNED_USERS = [1234567890, 0987654321]


@client.command()
async def check(ctx):
  #check if the user is banned
  if ctx.author.id in BANNED_USERS:
    await ctx.send("you are banned from using this command")
  #if the user is not banned
  else:
    await ctx.send("you are allowed to use this command")

@client.command()
async def blacklist(ctx, member: discord.Member):
  BANNED_USERS.append(member.id)
  await ctx.send(f"{member} has been added to the blacklist")

如果要使用.txt文件方式,请参见以下简单示例:

By this way the user id will be stored in the text file that means if you turned off your bot, the banned users They'll keep stored unlike the list one

@client.command()
async def check(ctx):
  file =  open("banned.txt", "r")
  members_banned = file.readlines()
  if str(ctx.author.id) in members_banned:
    await ctx.send("you are not allowed to use my commands")
  else:
    await ctx.send("you are allowed to use my commands")
  file.close()

@client.command()
async def blacklist(ctx, member: discord.Member):
  file =  open("banned.txt", "a")
  file.write(member.id)
  file.close()
  await ctx.send(f"{member} has been added to the blacklist")