Bot reaction to SPECIFIC words - discord.py

I'm having an issue trying to get my bot to respond to specific words. For example, having the words 'her', 'he', 'shop', and 'hop' trigger the bot to say "test". I've added these to a loop/list however the bot triggers the response on ANY word that has a sequence of the above letters. If someone says 'theater' the bot will respond because "tHEater". Here is the code I tried:
triggers = ['he', 'she', 'hop', 'shop']
for word in triggers:
if word in message.content:
await message.channel.send("test")
break
message.content == "she", etc does not work because this would only trigger on if someone ONLY typed 'she'.
What is happening? Is there a way for it to trigger on the specified sequence of letters?

Related

How to use options in discord.py?

I'm working on a discord bot that can send random memes, and I wanted to add a command for continuous feed according to a the amount of memes the user wants, for example /feed number:15, would send 15 memes.
The problem is how to make the option input work on the command, I've find some videos that helped me a little, but due to the other commands being híbrido commands, I can figure out how to make this one working.
This is what's I have so far:
#bot.hybrid_command(name = "feed", with_app_command = True, description = "Feeds a specific number of memes")
#app_commands.guilds(discord.Object(id = guild_id))
async def test1(interaction: discord.Interaction, number: int):
await interaction.response.send_message("It's working!")
The await line, obviously won't do any feed this way, I know, I did the feed part separated and it works, but I just did it this way for testing, so if I type the command and enter a number, it should return me "It's working!", But that never happens, I suppose it's maybe something to do with híbrido commands, but I really don't know, what am I missing?
I don't think the input option is the problem, because I see nothing wrong with it, but the thing that is surely wrong is that you're naming the first argument of the hybrid command interaction, which is wrong and can create confusion; the actual argument it should be is context or ctx. And that object is a discord.ext.commands.Context object.
You should rename it to ctx to avoid confusion.
#bot.hybrid_command(name = "feed", with_app_command = True, description = "Feeds a specific number of memes")
#app_commands.guilds(discord.Object(id = guild_id))
async def test1(ctx: commands.Context, number: int):
await ctx.send("It's working!")
You may want to see the official example here

botbuilder DialogTestClient 's sendActivity only accepts strings and not numbers

I am using the botbuilder DialogTestClient 's sendActivity method to send prompts to my bot while testing but the method only accepts string types and in my bot i use number promts to prompt the user for numbers . Do you have any idea on how i can overturn this problem ?
Thanks in advance
I'm a bit unclear if you are having this issue only for DialogTestClient or all Clients, but in nodejs you can just convert the string to number using Number(promptInput). If the promptInput is already a number, it will still work fine. I assume there is a similar function in C#.
Edit: Some additional context. You can take a look at userProfileDialog.js in multi-turn-prompt sample for an example. Essentially, NumberPrompt has a "succeeded" property in the recognizer that ensures you entered a number. You can use that plus whatever validations you want in the validator function. If it succeeds and is validated, a number, not a string, is passed to the next step in your dialog.
If the error is coming when you are trying to repeat back the prompt value to the user, you need to convert it to a string. I favor using the backtick for this (template string/literal), e.g.
await step.context.sendActivity(`You entered ${step.result}`);
where step.result is the numberPrompt result.

How to make a discord command with arguments?

I'm new to the coding and stuff and I want to know if there are any tutorials or pages where I can solve this:
I want to make a discord command that looks like this !acz map Lasius flavus where: !acz is the prefix, map is the command and Lasius flavus are two arguments.
Bot responds with message that is a link with the two arguments, that should look like this: https://antmap.coc.tools/images/Lasius.flavus.png
that means that we get a reply on discord that is a picture.
I want to be able to type in my discord !acz map Genus species - and bot responds with https://antmap.coc.tools/images/Genus.species.png where the first letter of Genus is capital, just like in the example.
I'm adding a picture with what I have in mind, where ? is prefix, map is command and Lasius flavus is Genus species
(no, I already asked for the code)
Thanks for your help!
#bot.command(brief="Za map napiš Rod a druh a vyskočí ti mapa výskytu!")
async def map(ctx, *args):
await ctx.channel.send('https://antmap.coc.tools/images/{}.png '.format('.'.join(args)))
this was the way and reading through https://www.programiz.com/python-programming/methods/string/replace helped me! eve tho I didn't use the replace()! I just had to change a few pieces in a code that sent noarguments and arguments:
#bot.command()
async def map(ctx, *args):
await ctx.channel.send('{} arguments: {}'.format(len(args), ', '.join(args)))

How do i check for multiple terms in message.content.lower

I'm programming a bot to stop my friends from playing league, but I can't figure out a way to check that multiple words are in the message.
if 'league' in message.content.lower():
response = random.choice(Response)
await message.channel.send(response)
What I'm doing here, is copying pasting this and changing the league word to another term. How do I make it just one line of code instead of a whole 100 lines?
if you mean multiple seperate words you could use the built-in any() function. You could also use the "or" keyword.
You can take use of the any() function:
some_words = ['word1', 'word2', 'word3']
if any(word in message.content.lower() for word in some_words):
...

Letters in DTMF | GRXML | Multiple Keypress on same number

Hi i need to know whether we can use letters(alphabets) in dtmf or touchtone in ivr application(genesys).if possible how can we use it?
FYI.,
i came to know after reading several forums,i can use the code which is given below.i need to know whether it is correct.if wrong let me know the grammar code
I need the scenario like if press '2' one time,i need 'a' and if press '2' two times i need 'b',etc..,
[(dtmf-2)] = 'a'
[(dtmf-2 dtmf-2)] = 'b'
[(dtmf-2 dtmf-2 dtmf-2)] = 'c'
In the following link,we have ABCD separate.whether it is available in all phones?
http://nemesis.lonestar.org/reference/telecom/signaling/dtmf.html
This is an old technique for spelling things out to an IVR application using DTMF. All phones use DTMF to transmit what keys are pressed. It will work on any IVR but it is up to the application developer of the IVR application to translate what the digits mean, and you need to give the user some direction on how to do this in the voice prompts. It is a very error prone method and it is best to give the user feedback on what you think they are trying to enter. But this is all we had before speech recognition came along.
Basically this is just using the letters on telephone keys as the guide. The letters "A", "B" and "C" are on key "2". You are telling them to press "2" the number of times that the letter appears in sequence on the key (i.e. "A" is first, "B" is second, and "C" is third). This method works fine for getting a single letter but it does not work so well for multiple letters unless you have the user pause for certain length of time to indicate they are finished. The IVR takes the length of silence as the ending of inputting a letter.
Another technique is to use two key presses for each letter, again using the sequence the letters appear on the number key as the guide. So the letter "A" would be 21, "B" is 22, "C" is 23, "D" is 31, etc... This technique does not require long pauses between entering a letter because the IVR knows there will be two key presses for each letter.

Resources