【问题标题】:Unban ID | I've used an unban command but still cant unban with an ID解禁ID |我使用了解禁命令,但仍然无法使用 ID 解禁
【发布时间】:2021-03-14 23:13:06
【问题描述】:

这是我目前正在使用的代码...非常好,但我真的想用 ID 解禁,因为这对我个人来说更容易。

当前命令在 Cog 文件中...

import discord
from discord.ext import commands

class unban(commands.Cog):

    def __init__(self, client):
        self.client = client
    @commands.command()
    @commands.has_permissions(administrator=True)
    async def unban(self, ctx, *, member : discord.Member):
        banned_users = await ctx.guild.bans()
        member_name, member_discriminator = member.split("#")

        for ban_entry in banned_users:
            user = ban_entry.user

            if (user.name, user.discriminator) == (member_name, member_discriminator):
                await ctx.guild.unban(user)
                unban = discord.Embed(title='UnBan Hammer Has Spoken! :boom:', description=f'**Moderator:** {ctx.author}\n **User UnBanned:** {member}\n', color=0x10940b)
                unban.set_author(name="Moderating Action", icon_url=ctx.author.avatar_url)
                await ctx.send(embed=unban)
                return

def setup(client):
    client.add_cog(unban(client))

那么,有什么想法吗???

【问题讨论】:

    标签: discord.py discord.py-rewrite python-3.8


    【解决方案1】:
    async def unban(self, ctx, id: int) :
            user = await client.fetch_user(id)
            await ctx.guild.unban(user)
            await ctx.send(f'{user} has been unbanned')
    

    这应该适合你,你可以个性化更多,但这只是你需要的主要代码。

    【讨论】:

      【解决方案2】:

      试试

      async def unban(self, ctx, *, member : discord.User):
          await ctx.guild.unban(discord.Object(id = member.id))
          unban = discord.Embed(title='UnBan Hammer Has Spoken! :boom:', description=f'**Moderator:** {ctx.author}\n **User UnBanned:** {member}\n', color=0x10940b)
          unban.set_author(name="Moderating Action", icon_url=ctx.author.avatar_url)
          await ctx.send(embed=unban)
      

      【讨论】:

      • 它对我不起作用...感谢您的帮助。
      • 怎么没用?你能告诉我你是如何实现的吗?如果你能告诉我,我可以帮忙。
      • 这不起作用,因为您的转换器试图将其转换为discord.Member,这是不可能的。当一个人被禁止时,他们不再是该公会的一部分,因此他们不能成为guild member
      猜你喜欢
      • 2021-03-26
      • 2020-12-21
      • 2020-11-15
      • 2020-10-13
      • 2021-04-18
      • 2021-01-18
      • 1970-01-01
      • 2021-07-27
      • 2021-02-02
      相关资源
      最近更新 更多