user202325
user202325

Reputation: 1

Bot discord with python

How can I make it so that when someone who is not an administrator and runs the 'cls' command gives him a message like for example you are not an administrator, sorry

Python code

@bot.command()
@commands.has_permissions(manage_messages=True)
async def cls(ctx, Quantity= 10000):
    if manage_messages == False:
        await ctx.send('You are not an administrator, you cannot run this command.')
    await ctx.channel.purge(limit = Quantity)

Help I don't know how to do it.

Upvotes: 0

Views: 99

Answers (2)

Alex Walters
Alex Walters

Reputation: 1

This is how I would do it to check if the author of the message has admin permissions in your case.

if ctx.message.author.guild_permissions.administrator:
    await ctx.channel.purge(limit=Quantity)
    await ctx.send('Deletion success! Deleted ' + Quantity + ' messages.')
else:
    await ctx.send('You are not an administrator, you cannot run this command.')

Upvotes: 0

pandafriend
pandafriend

Reputation: 11

import discord
import asyncio
from discord.ext.commands import Bot

client = Bot(description="My Cool Bot", command_prefix="!", pm_help = False, )
@client.event
async def on_ready():
  print("Bot is ready!")
  return await client.change_presence(game=discord.Game(name='My bot'))

@client.command(pass_context = True)
async def whoami(ctx):
    if ctx.message.author.server_permissions.administrator:
        msg = "You're an admin {0.author.mention}".format(ctx.message)  
        await client.send_message(ctx.message.channel, msg)
    else:
        msg = "You're an average joe {0.author.mention}".format(ctx.message)  
        await client.send_message(ctx.message.channel, msg)
client.run('Your_Bot_Token')

Upvotes: 1

Related Questions