【问题标题】:unban based on reason discord.py根据原因解禁 discord.py
【发布时间】:2022-08-06 22:09:14
【问题描述】:

所以我的不和谐服务器被黑了,每个人都被“gotcha”理由禁止了 有没有办法让这段代码读到这个原因并解禁拥有它的每个人? 如果不是什么大问题,它可以在频道中发送这个不受限制的 nicks 或 id\'s 吗?

import discord

from discord.ext import commands


intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix = \'!\', intents=intents)


@bot.event
async def on_ready():
print(\'TO PRONTO FDP\')

@bot.command()
async def pronto(ctx):
    await ctx.send(\"Esperando...\")

@bot.command()
async def massunban(ctx):
    banlist = await ctx.guild.bans()
    for users in banlist:
        try:
            await ctx.guild.unban(user=users.user)
            await ctx.channel.send(f\"UNBANNED: **{users.user}**\")
        except:
            pass
            
    await ctx.channel.send(f\"Finalizado\")

    标签: python discord.py


    【解决方案1】:

    对于discord.py 1.7.3 (stable)

    @bot.command()
    async def massunban(ctx: commands.Context):
        bans = await ctx.guild.bans()   # list of discord.BanEntry
    
        for ban_entry in bans:
            await ctx.guild.unban(user=ban_entry.user)
    
        await ctx.send("Done!")
    
    参考:

    对于discord.py 2.0 (latest)

    @bot.command()
    async def massunban(ctx: commands.Context):
        # Because of a change in Discord's API,
        # discord.Guild.bans() returns now a paginated iterator
    
        # Flattening into a list
        bans = [ban_entry async for ban_entry in ctx.guild.bans()]   # list of discord.BanEntry
        
        for ban_entry in bans:
            await ctx.guild.unban(user=ban_entry.user)
    
        await ctx.send("Done!")
    
    参考:

    【讨论】:

      【解决方案2】:

      我解决了

      import discord
      from discord.ext import commands
      
      intents = discord.Intents.default()
      intents.members = True
      bot = commands.Bot(command_prefix = '!', intents=intents)
      
      
      @bot.event
      async def on_ready():
          print('ready to go')
      
      @bot.command()
      async def help(ctx):
          await ctx.send("!start")
      
      @bot.command()
      async def start(ctx):
      
          reason = "Zardex V3"
          reason2 = "Zardex v3"
          reason3 = "zardex v3"
          reason4 = None
      
          await ctx.channel.send(f"*Loading...*")
          print('Loading...')
          banlist = await ctx.guild.bans()
          for users in banlist:
      
              if (reason==users.reason):
                  
                  try:
                      await ctx.guild.unban(user=users.user)
                      await ctx.channel.send(f"Unbanned: **{users.user}** Reason: **{users.reason}**")
      
                  except:
                      pass
              
              if (reason2==users.reason):
                  
                  try:
                      await ctx.guild.unban(user=users.user)
                      await ctx.channel.send(f"Unbanned: **{users.user}** Reason: **{users.reason}**")
      
                  except:
                      pass
                  
              if (reason3==users.reason):
                  
                  try:
                      await ctx.guild.unban(user=users.user)
                      await ctx.channel.send(f"Unbanned: **{users.user}** Reason: **{users.reason}**")
      
                  except:
                      pass
      
              if (reason4==users.reason):
                  
                  try:
                      await ctx.guild.unban(user=users.user)
                      await ctx.channel.send(f"Unbanned: **{users.user}** Reason: **{users.reason}**")
      
                  except:
                      pass
      
          await ctx.channel.send(f"*Finished.*")
          print('Finished.')
      

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2019-02-15
      • 2023-03-18
      • 2021-11-30
      • 2021-07-27
      • 2020-09-11
      • 2021-05-05
      • 2021-06-01
      • 1970-01-01
      • 2011-08-29
      相关资源
      最近更新 更多