如何让代码中的错误出现在我的终端中

问题描述 投票:0回答:1

您好,我的代码有问题我有一个代码可以发出警告并查看某人的警告数量,但我的代码中有错误

这里是:

from discord_slash import SlashCommand
slash = SlashCommand(client, sync_commands = True)
  for guild in bot.guilds:
    async with aiofiles.open(f"{guild.id}.txt", mode="a") as temp:
      pass
  client.warnings[guild.id] = {}
  for guild in client.guilds:
    async with aiofiles.open(f"{guild.id}.txt", mode="r") as file:
      lines = await file.readlines()
      for line in lines:
          data = line.split(" ")
          member_id = int(data[0])
          admin_id = int(data[0])
          reason = " ".join(data[2]).strip("\n")

          try:
            client.warnings[guild.id][member_id][0] += 1
            client.warnings[guild.id][member_id][1].append(admin_id, reason)
           @client.event
           async def on_guild_join(guild):
             client.warnings[guild.id] = {}
           @client.command()
           @commands.has_permissions(kick_members = True)
           async def warning(ctx, member: discord.Member, *, reason = "Aucune raison n'a été donné"):
             await ctx.message.delete()
             try:
               first_warning = False
               client.warnings[ctx.guild.id][member.id][0] += 1
               client.warnings[ctx.guild.id][member.id][1].append((ctx.author.id, reason))

             except KeyError:
                 first_warning = True
                 client.warnings[ctx.guild.id][member.id] = [1, [(ctx.author.id, reason)]]

                 count = client.warnings[ctx.guild.id][member.id][0]
      
                 embed = discord.Embed(title = "**Nombre de warn**", description = "Un modérateur a frappé !", url = "https://discord.com/api/oauth2/authorize?client_id=947274542424936508&permissions=8&scope=bot", color=0xfa8072)
                embed.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url, url = "https://discord.com/api/oauth2/authorize?client_id=947274542424936508&permissions=8&scope=bot")
                 embed.set_thumbnail(url = "https://cdn3.emoji.gg/emojis/3968-discord-banhammer.png")
                 embed.add_field(name = "Membre", value = member.mention, inline = True)
                 embed.add_field(name = "Nombre de warn", value = count, inline = True)
                 embed.add_field(name = "Modérateur", value = ctx.author.name, inline = True)
                 embed.set_footer(text = (funFact))
                 await ctx.send(embed = embed)


           @client.command()
           @commands.has_permissions(kick_members = True)
           async def warn(ctx, member: discord.Member, *, reason = "Aucune raison n'a été donné"):
             embed = discord.Embed(title = "**Warn**", description = "Un modérateur a frappé !", url = "https://discord.com/api/oauth2/authorize?client_id=947274542424936508&permissions=8&scope=bot", color=0xfa8072)
             embed.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url, url = "https://discord.com/api/oauth2/authorize?client_id=947274542424936508&permissions=8&scope=bot")
             embed.set_thumbnail(url = "https://cdn3.emoji.gg/emojis/3968-discord-banhammer.png")
             embed.add_field(name = "Membre", value = member.mention, inline = True)
             embed.add_field(name = "Raison", value = reason, inline = True)
             embed.add_field(name = "Modérateur", value = ctx.author.name, inline = True)
             embed.set_footer(text = (funFact))
             await ctx.send(embed = embed)

我知道有错误,因为它不起作用,但在我的命令终端中没有报告错误

我已经尝试了一切,但我从未找到字母的解决方案,请

python discord.py bots
1个回答
0
投票

如果你像我一样懒,我建议你使用简单的打印

if #do stuff
print(Error) #It doesn't really need any code it will print if it works

打印实际上并不需要代码,因为如果命令本身有效,它就会打印。

© www.soinside.com 2019 - 2024. All rights reserved.