#๐Ÿ”’ Discord bot

36 messages ยท Page 1 of 1 (latest)

restive glacierBOT
#

@mighty wyvern

Python help channel opened

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.

valid radish
#

@mighty wyvern mabe try this

#

!paste

restive glacierBOT
#
Pasting large amounts of code

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.

mighty wyvern
#

thank you!

untold grove
#

whys the original message deleted

#

oh wait nvm

mighty wyvern
#

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

mighty wyvern
#

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

mighty wyvern
#

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

thick dust
#

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

mighty wyvern
# thick dust That can't be the full code

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

mighty wyvern
#

Also, for reffereance what is this "topic" called so I could research it some more?

pure mulch
#

And when the user "connects" it will append the authors ID to the list and etc

#

You can probably do it with decorators

mighty wyvern
pure mulch
mighty wyvern
# pure mulch You can probably do it with 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

mighty wyvern
thick dust
# mighty wyvern Also, for reffereance what is this "topic" called so I could research it some mo...

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")
mighty wyvern
untold grove
pure mulch
untold grove
pure mulch
untold grove
restive glacierBOT
#
Python help channel closed

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.