#๐ Discord bot
36 messages ยท Page 1 of 1 (latest)
@mighty wyvern
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
thank you!
I want to make it so it "locks" all of the commands from a bot which hasn't had it's session "connected" by a user
for example, the ping command would not warrant any type of response unless a user has ran ?connect <sessionID> to connect to that bots session
whats the error?
in which case the bot is "active" and the rest of its commands can be used until the user runs "disconnect" which will "lock" it out of all commands until it connected again
there isn't one, I haven't added any of the logic to do it yet
I'm unsure how, I've tried a few times and it's usaly all proceeding commands become unrecognized
preferably I don't want to edit each proceeding command to check if the connect flag is True, I'd rather have it so the flag being True can be called in a singular line per function if possible to allow them to run
That can't be the full code
If you want to toggle commands you need to add a check to each command and you need to implement what exactly it will check. Usually you will keep track of this as a bot variable in the bot class instance
It isn't its just the part of the code that I'm having issues implementing the logic with, for this example im using the ping command to test on in place of my other functions which I have in my main code
How would I go about adding the actual logic to make it so commands won't run if the Connected variable is False for example? Can I add this logic into a function and just call it upon every command
Also, for reffereance what is this "topic" called so I could research it some more?
You could probably just make a dictionary having the command names as the key having an empty list as it's value.
And you can check if the authors ID is present in the list of the command's name or not
And when the user "connects" it will append the authors ID to the list and etc
You can probably do it with decorators
I see, what is the actual like function within the discord module to make it ignore commands if the condition of the author ID not being present in this case is met
there isn't any ready made one as far as ik you can just do it with a simple if statement and to make stuff less repetitive you can make use of custom decorators
I tried to do a similar thing via decorators and kept running into the issue the later commands where not being recognised once connected. Is this due to where I had the check?
I had it in the format
@bot.command()
@checkifvalid
async def mycommand(ctx):
#example code
Okay thanks! I will give this a try now
OOP, object oriented programming? You are creating pseudo-sessions that don't seem to have any real purpose (at least from the code you shared) other than locking commands. If you want commands to be available on a by-user basis, Jiggly Balls has suggested a good approach. Have a connect/activate command that adds the user to an "allowed users" list or dictionary (storing data in whatever way is most convenient for you), saved in the bot instance, and then on command usage add a check. A simple way would be something like:
@bot.command()
async def ping(ctx):
if ctx.author.id not in allowed_users:
return await ctx.send("Not allowed!")
else:
await ctx.send(f"Ping: {round(bot.latency * 1000)}ms")
Thank you! I will try this approach now and let you know how I get on
why is this guy here ๐ญ
I'm everywhere
are you and reject done with unibot
No lmao we have a long way to go

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.