@bot.command()async def unban(ctx, id: int): user = await bot.fetch_user(id) async for entry in ctx.message.guild.audit_logs(limit=None, user=user, action=discord.AuditLogAction.ban): await ctx.guild.unban(entry.target) print("Unbanned ", entry.target, entry.target.id, "Banned by ", entry.user, "Entry ID: ", entry.id)編寫上面的函數是為了獲取用戶 ID,并將其傳遞給audit_logs() 以獲取該用戶禁令的所有審核日志條目。然后我嘗試使用入口目標發(fā)出 unban() 。當我在我的私人服務器上測試它時,這是有效的。我邀請了一堆機器人,自己禁止了一些機器人,然后用一個機器人禁止了其他機器人。我使用自己的用戶 ID 運行該命令,BattleNubBot 僅取消了我已禁止的用戶。我認為我修改的服務器的管理員可以邀請我的機器人查看審核日志并禁止權限,然后我們在那里嘗試了該命令。我們得到:忽略命令 unban 中的異常:Traceback (most recent call last): File "C:\Users\Joey\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File ".\BattleNubBot.py", line 21, in unban await ctx.guild.unban(entry.target) File "C:\Users\Joey\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\guild.py", line 1892, in unban await self._state.http.unban(user.id, self.id, reason=reason) File "C:\Users\Joey\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\http.py", line 243, in request raise NotFound(r, data)discord.errors.NotFound: 404 Not Found (error code: 10026): Unknown Ban
1 回答

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
我不知道為什么要audit_logs取消會員封禁,有更好的方法嗎
@client.command()
async def unban(ctx, member):
banned_users = await ctx.guild.bans()
member_name, member_discriminator = member.split("#")
for banned_member in banned_users:
user = banned_member.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
如果您只想執(zhí)行取消禁止命令,這將起作用。你可以像這樣使用它.unban someone#1234。
添加回答
舉報
0/150
提交
取消