有人知道为什么我的解禁命令不起作用吗? |Discord.py



我的代码将运行,但是当我输入命令时,什么也没有发生。有人知道怎么解决这个问题吗?

@client.command()
@commands.has_permissions(ban_members = True)
async def unban(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.banned_users

if (user.name,user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
embed=discord.Embed(title=" ✅ *Sucessfully unbanned*  @" + member.name + '#' + 
member.discriminator, color=0x00ff4b)
await ctx.send(embed=embed)
print('[LOGS] Successfully banned @' + member.name + '#' + member.discriminator)

我看了一下,给了这个机会:

async def unban(ctx, *, member):
banned_users = await ctx.guild.bans()
try:
member_name, member_discriminator = member.split("#")
except:
await ctx.send(":x: Should look like this: User#0001")
return
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
else:
await ctx.send(":thinking: Hmm, seems like that person is already unbanned or does not exist!")
return

据我所知,除了我发现的两个主要问题外,该命令应该工作正常:

  • 你在做user = ban_entry.banned_users时应该是user = ban_entry.user

  • 您提供的代码没有缩进(这会抛出错误,但以防万一,这里有一个更正的&缩进版)

@client.command()
@commands.has_permissions(ban_members = True)
async def unban(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)
embed=discord.Embed(title=" ✅ *Sucessfully unbanned*  @" + member.name + '#' + member.discriminator, color=0x00ff4b)
await ctx.send(embed=embed)
print('[LOGS] Successfully banned @' + member.name + '#' + member.discriminator)

相关内容

  • 没有找到相关文章

最新更新