使用 audit_log 条目来解禁不在特定服务器上工作的目标用户 - discord.py
Using audit_log entry to unban the target user not working on particular server - discord.py
@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() 以获取该用户禁令的所有审核日志条目。然后我尝试使用入口目标发出 unban()。当我在我的私人服务器上测试它时,它起作用了。我邀请了一堆机器人,自己禁止了一些,然后用一个机器人禁止了其他机器人。我 运行 使用我自己的用户 ID 命令,BattleNubBot 只取消了我已经禁止的用户。
我想有一个服务器的管理员我 mod 邀请我的机器人查看审计日志,并禁止权限,然后我们在那里尝试了命令。我们得到:
忽略命令解禁中的异常:
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
我不知道你为什么要用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)
如果你只是想执行一个解除禁令的命令,这会起作用。您可以像 .unban someone#1234
.
一样使用它
@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() 以获取该用户禁令的所有审核日志条目。然后我尝试使用入口目标发出 unban()。当我在我的私人服务器上测试它时,它起作用了。我邀请了一堆机器人,自己禁止了一些,然后用一个机器人禁止了其他机器人。我 运行 使用我自己的用户 ID 命令,BattleNubBot 只取消了我已经禁止的用户。
我想有一个服务器的管理员我 mod 邀请我的机器人查看审计日志,并禁止权限,然后我们在那里尝试了命令。我们得到:
忽略命令解禁中的异常:
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
我不知道你为什么要用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)
如果你只是想执行一个解除禁令的命令,这会起作用。您可以像 .unban someone#1234
.