I was able to get a Discord bot up and running and have a few commands. One of the commands I have is an "!live" command that I can use to make the bot say "@here I'm live right now - urlhere"
How do I go about making the bot check user permissions so not just anyone can use the command?
This is the code I currently have. All it does is reply when a user uses the command "!live"
if p_message == "!live":
return "I'm live on Twitch - urlhere"
Use the actual prefix function that comes with discord.py. I haven't done discord bots in a long time but I can contribute to this.
For example, initiating the prefix is easy.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = ">")
The client is the actual bot in the discord, and it has a prefix. (In this case, I set it to >)
Now how to define a function. The basic function has this syntax:
@client.command()
async def commmandName(ctx, otherparameters):
pass
If you want a function with permissions,
@client.command()
@commands.has_permissions(manage_roles = True) //the permissions
async def function(ctx):
pass
By the way, ctx means context. If you want the author of the message,
ctx.author
If channel,
ctx.channel
and such.
It can also be used in replies,
await ctx.reply
When you want to send a packet to the discord servers, use
await yourFunction
Await just makes it less likely for your program to return errors and stuff to not work.
For further information on command making you can refer to the docs
How to make an efficient command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With