【问题标题】:I'm trying to make an unban command but this error shows up. "inconsistent use of tabs and spaces in indentation"我正在尝试创建一个 unban 命令,但出现了这个错误。 “缩进中制表符和空格的使用不一致”
【发布时间】:2021-03-14 21:49:18
【问题描述】:

我试图修复它,但仍然没有。我 100% 确定问题出在 unban 文件上。因为一旦我删除嵌入,机器人就可以正常工作,所以是的,让我只显示代码......

主文件:

import discord
import os
import random
from discord.ext import commands

client = commands.Bot(command_prefix = '/')

@client.command()
async def load(ctx, extension):
    client.load_extension(f'cogs.{extension}')

@client.command()
async def unload(ctx, extension):
    client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
      client.load_extension(f'cogs.{filename[:-3]}')

client.run(My current key)

Cog Unban 文件:

import discord
from discord.ext import commands

class unban(commands.Cog):

    def __init__(self, client):
        self.client = client

    @commands.command()
    @commands.has_permissions(ban_members=True)
    async def unban(self, ctx, *, 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)
                unban = discord.Embed(title='UnBan Hammer Has Spoken! :boom:', description=f'**Moderator:** {ctx.author}\n **User UnBanned:** {member}, color=0xbd2929)
                await ctx.channel.send(embed=unban)

def setup(client):
    client.add_cog(unban(client))

【问题讨论】:

  • 您是否对同一个文件使用了不同的编辑器,或者您是否从互联网上复制了一些 sn-ps?

标签: discord.py discord.py-rewrite python-3.8


【解决方案1】:

您的 cog 文件中的一行似乎缺少 ',这应该可以解决它:

unban = discord.Embed(title='UnBan Hammer Has Spoken! :boom:', description=f'**Moderator:** {ctx.author}\n **User UnBanned:** {member}', color=0xbd2929)

【讨论】:

  • 非常感谢!
猜你喜欢
  • 2020-08-10
  • 1970-01-01
  • 2022-11-11
  • 2022-06-26
  • 2023-02-10
  • 1970-01-01
  • 2012-10-10
  • 2011-08-06
  • 1970-01-01
相关资源
最近更新 更多