每当我在 VSC 中运行我的代码时,我的终端中都没有出现任何错误,所以我不知道从哪里开始。
当我运行命令时,它应该是 !massban 。这样做时,它应该检查以确保用户在服务器中或不在服务器中,并检查以确保给出原因。之后,它应该向用户发送一条嵌入消息,告诉他们他们被禁止及其原因,同时向日志通道发送另一个嵌入消息,以显示谁对用户进行了操作及其原因。最后,用户将被禁止,同时显示有多少成功的禁令/失败的数量。
不幸的是,在使用此命令时,它不会检查成员是否在服务器中,也不会检查是否包含原因。它只会禁止给定的第一个 ID,不会向用户发送嵌入消息,并且只会向 mod 日志通道发送一个日志,而不会说明有多少成功的禁令/失败的数量。 (我使用 alt 帐户对此进行了测试,它们都能够从我的服务器接收消息。)
这是我的代码:
@client.command()
@commands.has_any_role("Head Honcho", "Discord Moderator")
async def massban(ctx, member : commands.Greedy[discord.Member], *, reason: Optional[str]):
if member is None:
return await ctx.send("This member could not be found, or you did not provide an ID.")
if reason is None:
return await ctx.send("Please provide a reason for banning this user.")
success = 0
failures = 0
for user in member:
try:
embed = discord.Embed(title = "You have been **banned** from ? Cold's Jamboree ?" , description = "A moderator has banned you regarding your behavior." , color = discord.Color.from_rgb(204,0,0))
embed.add_field(name = "Reason:", value = "{reason}".format(reason=reason) , inline = True )
embed.set_thumbnail(url=ctx.guild.icon_url)
try:
await member.send(embed=embed)
await ctx.guild.ban(user, delete_message_days=1)
except discord.HTTPException:
pass
success +=1
except discord.HTTPException:
failures +=1
finally:
channel = client.get_channel(820100484358471701)
embed = discord.Embed(title = f"", description = "**[?] A 'mass ban' has been issued.**", color = discord.Color.from_rgb(204,0,0), timestamp = ctx.message.created_at)
embed.add_field(name = f" `{ctx.author.name}` has banned `{user.name}`.\n\nReason:", value = "{reason}".format(reason=reason))
embed.set_author(name = f"{user} ({user.id})", icon_url = user.avatar_url)
embed.set_footer(icon_url = ctx.author.avatar_url, text = "Modlog created ")
try:
await channel.send(embed=embed)
except discord.HTTPException:
pass
if ctx.channel.id == 805651955841236993:
reaction_emote = ("<:Checkmark:820467149554319410>")
await ctx.message.add_reaction(reaction_emote)
await ctx.send("Massbanned " + str(success) + " members.\n{}".format(f"Failed {failures} members." if failures else ""))
如果有人能帮助我,我将不胜感激。由于 VSC 没有给我任何错误,我对正在发生的事情感到困惑,因为它应该工作。