Quick
Quick

Reputation: 11

Have an error with nextcord slash commands

So i am trying to add a support to a slash commands but for some reason it says: AttributeError: 'NoneType' object has no attribute 'delete' its mostly coming from await ctx.message.delete(ctx.delete) and i cant find any solutions. here is my code:

@client.slash_command(name="tempmute", description="temporary mutes a member from the server")
async def tempmute(ctx, member: nextcord.Member,time):
    muted_role=nextcord.utils.get(ctx.guild.roles, name="Muted")
    time_convert = {"s":1 , "m":60, "h":3600,"d":86400}
    tempmute= int(time[0]) * time_convert[time[-1]]
    await ctx.message.delete(ctx.delete)
    await member.add_roles(muted_role)
    embed = nextcord.Embed(description= f"✅ **{member.display_name}#{member.discriminator} muted successfuly**", color=nextcord.Color.green())
    await ctx.send(embed=embed, delete_after=5)
    await nextcord.sleep(tempmute)
    await member.remove_roles(muted_role)    

Upvotes: 0

Views: 627

Answers (1)

Lukas Thaler
Lukas Thaler

Reputation: 2720

A slash command is invoked without a message and there's nothing to delete, i.e. ctx.message is None (hence the error). The await ctx.message.delete(ctx.delete) line is completely redundant in a slash command setting and can simply be removed

Upvotes: 1

Related Questions