I am new to Discord.py and am trying to make a command for cogs that allow me to load, unload, and reload the cogs using a command.
I have the command done, but now I'm trying to make it only work when I'm the one using it, or my alt account. I can make it work for my main, but then it ignores my alt. How can I make it work for both?
trusted = ('account1', 'account2', 'account3')
@client.command()
async def load(ctx, extension):
if ctx.author.id == trusted:
client.load_extension(f'cogs.{extension}')
await ctx.reply(f'loaded {extension}')
I was able to get it working using 'else' and 'if', though that just doubled the length of the otherwise simple code, and I know this way can work somehow, I'm just now sure how to do it.
As I said, the command works with 'account1', though it will ignore the others. How would I fix it so it works on the others accounts?
Thank you for any help!
CodePudding user response:
The problem is that you did not make a proper list ([]
) and did not check all the entries in it.
If you store something like an ID in the list, simply store them as they are and leave out your quotation marks ("
).
Your new code:
trusted = [ID1, ID2, ID3...] # Create a list of IDs
@client.command()
async def load(ctx, extension):
if ctx.author.id in trusted: # We check if the author.id is IN the list
#Do what you want to do