#You cannot warn yourself

1 messages · Page 1 of 1 (latest)

north garnet
#

hello , i made a slash command and my code has a bug which user can warn himself

    @commands.slash_command()
    @commands.has_permissions(manage_messages=True)
    async def warn(self, ctx, user: discord.Member, *, reason: str):
        '''Warn a member via DMs'''
        warning = f'You have been warned in **{ctx.guild}** by **{ctx.author}** for {reason}'
        if not reason:
            warning = f'You have been warned in **{ctx.guild}** by **{ctx.author}**'
        try:
            await user.send(warning)
        except discord.Forbidden:
            return await ctx.respond('The user has disabled DMs for this guild or blocked the bot.')
        await ctx.respond(f'**{user}** has been **warned**')
past kestrel
#

You can check is ctx.author.id == user.id?

north garnet
past kestrel
#

With an error?

north garnet
past kestrel
#

You still need to respond to the interaction. If the user is the same as the author ctx.respond with a message saying you cant warn yourself

north garnet
past kestrel
#

Does the command show up in the / list?

north garnet
#

but when i warn myself it shows nothing

#

it doesn't respond

past kestrel
#

When you say it shows nothing do you mean nothing is sent or under your /warn ... command discord says this application did not respond?

past kestrel
#

Which one?

north garnet
past kestrel
#

Did you restart your bot?

north garnet
#

and i got api banned

#

now i connected to another bot to test

past kestrel
#

With the information you gave me there is no reason that

@commands.slash_command()
@commands.has_permissions(manage_messages=True)
async def warn(self, ctx, user: discord.Member, *, reason: str):
    '''Warn a member via DMs'''
    if ctx.author.id == user.id:
        await ctx.repond("You can't warn yourself", ephemeral=True)
        return

    warning = f'You have been warned in **{ctx.guild}** by **{ctx.author}** for {reason}'
    if not reason:
        warning = f'You have been warned in **{ctx.guild}** by **{ctx.author}**'
    try:
        await user.send(warning)
    except discord.Forbidden:
        return await ctx.respond('The user has disabled DMs for this guild or blocked the bot.')
    await ctx.respond(f'**{user}** has been **warned**')

Would not work.

#

With no errors

past kestrel
#

What about them?

north garnet
past kestrel
#

I still dont see the issue?

north garnet
past kestrel
#

Discord messed up the indentation you need to remove the spaces and replace it with indents

north garnet
#

sure