解禁 ID |我已经使用了 unban 命令,但仍然无法使用 ID 解禁

Unban ID | I've used an unban command but still cant unban with an ID

这是我目前正在使用的代码...它非常好,但我真的想用 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))

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

尝试

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

这应该适合您,您可以进行更多个性化设置,但这只是您需要的主要代码。