Hi i\'m new to python coding with discord and I have tried to make a command that tells the user if they are a admin or not but well... its not working in the slightest
Change
@client.command(name="whoami",description="who are you?")
async def whoami():
to
@client.command(pass_context=True)
async def whoami(ctx):
Then you can use ctx
to get all kinds of stuff like the user that wrote it, the message contents and so on
To see if a User
is an administrator do
if ctx.message.author.server_permissions.administrator:
which should return True
if the user is an an Administator
Your code should look like this:
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')