Discord bot commands - python-3.x

I've made a discord bot using python and I'd like to add a bug reporting command and some other commands so I was wondering how I could do this. For example User types: /report_bug and the bot responds: describe the bug. and then the User types in the bug. How could this be possible?
Here's a small snippet of the response code:
def handle_response(message) -> str:
p_message = message.lower()
if p_message == 'report_bug':
return 'Describe the bug'
#so here's where I'd like to take user input

You can't do anything after returning but assuming you just want to know how to get input:
Just add it as an argument to your command instead of making the bot ask for additional input afterwards. This makes the most sense, is the most user-friendly, and is the least pain to implement.
Use wait_for with a check.
Show a Modal where they can type whatever they want to.
Official examples for slash commands (with arguments): https://github.com/Rapptz/discord.py/blob/master/examples/app_commands/basic.py
Official example for a Modal: https://github.com/Rapptz/discord.py/blob/master/examples/modals/basic.py

Related

Discord.js message includes

Hi im currently adding some new features to a bot and it's been going great with some amazing progressions each day. I ran into an issue that i can't seem to solve even though i feel like the solution is right in front of me. In my code i have an if statement to check if a user has more matches won than 22 in the database, if so they are allowed to equip a certain background if not it returns an error message. I tried to do another if statement to check if a certain user is trying to run the command by matching their discord ID and for some reason it runs both the if statements when doing either command even though i used message.content.includes to specify what arguments it should look for in the command. Any help would be appreciated
According to the mozilla docs:
The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand.
This means that only the second operand in each if statement is being returned, ignoring message.content.includes().
Changing the , to && should fix the issue.
source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

kivy switch_to screen on if statement doesn't work

I could REALLY use your help with this one.
I'm trying to make a sort-of voice command operated menu for a toddler's learning app and kivy is giving me a headache
all of my screens are correctly defined and load as intended if the buttons are pressed but the voice commands, even though they register correctly and carry over their variables as intended they don't seem to have the desired effect when asked to act upon ScreenManager when the if statement is fulfilled
def on_enter(self):
....
Command.start()
Command.introMenu()
......
if Command.sel == "shapes":
ScreenManager().switch_to = "shapes"
elif Command.sel == "colours":
ScreenManager().switch_to = "colours"
......
else:
pass
the variable Command.sel is captured from a dependency, defined as a string and carried correctly as far as I can tell from the variables view in debugging
yet even though everything seems to be in order (in fact no error messages appear at all) the desired screen is not called when the if condition is met
what am I doing wrong here???
full code here
(please ignore the Greek bits in the code... it's just strings, imagine it's any other language for that matter...)
thank you!
issue resolved
correct command was
self.parent.current = "your_screen_name"
answer (eventually) found here

How to set value input() function in Brython, not confirm dialog?

My code:
a = input()
print(a)
I want set value from input not confirm dialog.
What should I do?
I don't think that'll work.
Brython translates to JavaScript, which will run in the browser in event driven mode.
This doesn't allow blocking console input.
Skulpt found a solution for that:
https://github.com/skulpt/skulpt/blob/master/doc/suspensions.txt
But if you want to do browser programming, probably the best is to use HTML inputs. A.f.i.k. Brython can cooperate with those.

Using a commandline argument to call a class method

Aplogies if I have the terminology all wrong; I am still learning the basics of Python. I have been unable to google this issue, probably in large part because I don't know the terminology..
So. I have built a class within a .py script with LOTS of methods/functions. To keep this remotely simple, I want to call these from a commandline argument. I have no idea how to explain it, and I can't find anhy examples, so I will try to demo it:
Take for example mute_on as the function that I want to call. I run the script with the function/method in the argument, like:
python3 ./myscript.py mute_on
I assume we'd import sys(?), define the class and the function, and create the relevant object from the class:
import sys
class TelnetAVR(PioneerDevice):
def mute_on(self, mute):
self.telnet_command("MO")
mypioneer = PioneerDevice('Pioneer AVR', '192.168.2.89', 8102, 10)
...and lastly I would like the commandline argument to call the method/function - instead of calling it explicitly like:
mypioneer.mute_volume()
..I want to use the arg (sys.argv[1]) to dynamically call the function, like:
mypioneer.{sys.argv[1]}()
Any ideas, kind people? I have been auto-referred to What is getattr() exactly and how do I use it? but I have no idea how that information can help me here.
I have tried setting cmnd = 'turn_off' and then the following failed...;
getattr(mypioneer, str(cmnd))
getattr(mypioneer, cmnd)
Thanks!
This answer seems a little basic, but I cannot complain as to its efficacy;
mypioneer = PioneerDevice('Pioneer AVR', '192.168.2.89', 8102, 10)
exp = 'mypioneer.' + sys.argv[1] + '()'
print('Executing: ' + exp )
exec(exp)
I gave up loking for a graceful answer, and simply constructed a string that I wanted to execute (exp) based on the commandline argument. Works great.. Home Assistant can use the same script to call 50 telnet controls over my Pioneer AVR.

Is there a module for getting user input from the command line in node.js?

First of all: I don't mean parsing arguments and options from the process.argv array, but prompting the user and handling input/output. I've looked through the Node.js official module list without finding any sections or subsections that mentions input. In fact a search for 'input' on that page only gets 1 result which has something to do with YAML.
Anyway, I suppose cli input should be asynchronous and I've solved this issue before using stdin.on('data') which was messy to say the least. This seems like a perfect task for a node module which could come with extra goodies such as progress bars, spinners, coloured output, input validation etc.
There probably are some modules out there that does this, but I can't find any of them.
Help!!
(To clarify, the only functionality I require is the simplification of handling user input)
Search for modules here: http://eirikb.github.com/nipster/
Prompt: https://github.com/jesusabdullah/node-prompt
Progress bar: https://github.com/substack/node-multimeter
Colors: https://github.com/Marak/colors.js
Input validation: https://github.com/chriso/node-validator
More input validation (webbish tho): https://github.com/caolan/forms
Also, if you want to write your own: http://nodejs.org/docs/latest/api/all.html#readline
#node.js IRC welcomes you: http://webchat.freenode.net/?channels=node.js

Resources