【问题标题】:The command tempmute is already an existing command or alias命令 tempmute 已经是现有命令或别名
【发布时间】:2021-10-27 12:13:57
【问题描述】:
class My_Cog(commands.Cog, name='Moderation'):
    def __init__(self, bot):
        self.bot = bot

    @client.command()#tempmute command
    async def tempmute(ctx, member: discord.Member, time: int, d, *, reason=None):
        guild = ctx.guild

        for role in guild.roles:
            if role.name == "Muted":
                await member.add_roles(role)

                embed = discord.Embed(title="muted!", description=f"{member.mention} has been tempmuted ", colour=discord.Colour.light_gray())
                embed.add_field(name="reason:", value=reason, inline=False)
                embed.add_field(name="time left for the mute:", value=f"{time}{d}", inline=False)
                await ctx.send(embed=embed)

                if d == "s":
                    await asyncio.sleep(time)

                if d == "m":
                    await asyncio.sleep(time*60)

                if d == "h":
                    await asyncio.sleep(time*60*60)

                if d == "d":
                    await asyncio.sleep(time*60*60*24)

                await member.remove_roles(role)

                embed = discord.Embed(title="unmute (temp) ", description=f"unmuted -{member.mention} ", colour=discord.Colour.light_gray())
                await ctx.send(embed=embed)

                return

大家好!什么是命令 tempmute 已经是现有命令或别名。在 Python 中?它有什么作用?当这个命令在课堂上时,我不明白为什么我不能创建一个 cog?它给了我一个错误。我不知道该怎么办

【问题讨论】:

  • 嗯,你有两个名为tempmute的命令吗?

标签: python discord discord.py bots categories


【解决方案1】:
class My_Cog(commands.Cog, name='Moderation'):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(aliases=['tempmute'])#tempmute command
    async def temp_mute(self, ctx, member: discord.Member, time: int, d, *, reason=None):
        guild = ctx.guild

        for role in guild.roles:
            if role.name == "Muted":
                await member.add_roles(role)

                embed = discord.Embed(title="muted!", description=f"{member.mention} has been tempmuted ", colour=discord.Colour.light_gray())
                embed.add_field(name="reason:", value=reason, inline=False)
                embed.add_field(name="time left for the mute:", value=f"{time}{d}", inline=False)
                await ctx.send(embed=embed)

                if d == "s":
                    await asyncio.sleep(time)

                if d == "m":
                    await asyncio.sleep(time*60)

                if d == "h":
                    await asyncio.sleep(time*60*60)

                if d == "d":
                    await asyncio.sleep(time*60*60*24)

                await member.remove_roles(role)

                embed = discord.Embed(title="unmute (temp) ", description=f"unmuted -{member.mention} ", colour=discord.Colour.light_gray())
                await ctx.send(embed=embed)

                return

您可以尝试这样做来消除错误,但请检查是否有另一个名为 tempmute 的命令。此外,在 cog 中,使用“@commands.command”。

【讨论】:

  • 现在我可以创建类别,但命令不起作用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-24
  • 2021-03-23
  • 2022-10-01
  • 2020-11-21
  • 2020-10-19
  • 1970-01-01
  • 2021-04-28
相关资源
最近更新 更多