首页 > 解决方案 > 命令 tempmute 已经是现有命令或别名

问题描述

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?它给了我一个错误。我不知道该怎么办

标签: pythondiscorddiscord.pybotscategories

解决方案


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”。


推荐阅读