trying to make a choose command (like pls choose) - discord.py

I've been trying to code a choose command like how dank memer has one but without the slash commands but the problem is i dont have that much coding knowledge to make the bot choose beetween 2 things so i did a code like this:
#bot.command(pass_context=True)
async def choose(ctx, *, message1, message2):
possible_responses = [
f"i choose {message1}",
f"i choose {message2}",
]
await ctx.send(random.choice(possible_responses) + " ")
the code worked but it only send "i choose" so how can i make my bot choose beetween 2 words and send the answer?

This is a very simple way of doing it,
#bot.command()
async def choose(ctx, option1, option2, option3):
choices = [option1, option2, option3]
await ctx.send(f"I choose, {random.choice(choices)}")

Related

Multiple SlashOptions Nextcord

I am trying to to create a command that that allows a user to select multiple options and then put them in an embed. So far I have been able to do this with one option but I want to do it with more as well. Is there a way to add multiple SlashOptions to a slash command and if so how might it be done. Thank you for all your help.
Here is what I currently have
async def announce(interaction: Interaction, buysell:str = SlashOption(
name="bto-stc",
choices={"BTO": "BTO", "STC": "STC"}),
stock:str,):
embed = nextcord.Embed(description=f"**Options Entry**", color=0x00FF00)
embed.add_field(name=f"** [🎟️] Contract:** *{buysell}* *{stock}*", value="⠀", inline=False)
await interaction.response.send_message(embed=embed, ephemeral=False)```
Here is what I would like the end product to look like.
https://i.stack.imgur.com/9SmIK.png
Your stock argument must be before your choices argument as for Python this argument is and optional argument and you can't have required arguments before optionals ones.
Also if you don't want your buysell argument to be optional you need to add a required argument set to True in your SlashOption object. And in your case you can also replace the choices argument in the SlashOptionobject by a list as the choices and the data you want from them are the same.
Example:
async def announce(interaction: Interaction, stock:str, buysell:str = SlashOption(
name="bto-stc",
choices=["BTO", "STC"],
required=True)):
embed = nextcord.Embed(description=f"**Options Entry**", color=0x00FF00)
embed.add_field(name=f"** [🎟️] Contract:** *{buysell}* *{stock}*", value="⠀", inline=False)
await interaction.response.send_message(embed=embed, ephemeral=False)

How can i get this condition to work properly | Discord.py

the intention was to when -rickroll is used and the bot is pinged it should say no u if not | update-> the user is the one who has to be pinged.
the it should send a gif and say (#the pinged) has been rickrolled lol
if user.id != 878176818564317184:
await ctx.send('https://tenor.com/view/rick-astley-rick-roll-dancing-dance-moves-gif-14097983')
await ctx.send(user)
await ctx.send('has been rickrolled lol')
else:
await ctx.send('No u')```
i don't know what is wrong with your code since you didn't post any information so i wrote this:
#bot.event
async def on_message(message):
if message.author == bot.user:
return
#refering to the message sent in discord and chaning it to lower case
msg = message.content.lower().replace(' ', '')
if msg.startswith('!help'):
if message.author.id != 878176818564317184:
await message.channel.send('''https://tenor.com/view/rick-astley-rick-roll-dancing-dance-moves-gif-14097983''')
await message.channel.send(f'''{message.author.mention} you have been rickrolled lol''')
else:
await message.channel.send('No u')
Supposing ctx is the first parameter of the discord.py on_message event, then the variable ctx is an instance of the discord.message.Message class which contains no method called send, thus ctx.send(user) is not going to work.
Assuming you want your bot to respond in the same text channel the message was sent to, you can take advantage of the channel attribute from the Message class, which contains a send method that will allow you to send messages.
Therefore a possible solution would be:
await ctx.channel.send("Your message")
A different but less usual approach would consist on the usage of the Message.reply method. It would be like this:
await ctx.reply("Hey, I'm replying to your msg!")
The biggest difference between the two would be that the second uses Discord's reply feature, hence the user who sent the message in first place would be pinged.
You can find this and more information in the official documentation of the library.
Please read https://stackoverflow.com/help/how-to-ask before posting another question, it will make easier for others to understand the problem you ran into and help you.

Grabbing user's messages with command

im writing a very simple discord py bot command, which returns the sentence written by user after saying $send_back :
#client.command()
async def send_back(ctx,sentence):
await ctx.send(sentence)
i want my bot to return the full sentence, but the problem is that it only returns the first word of the sentence:
User : $send_back whats upp!
Bot : whats
what is the best way to solve this problem? i don't want to use client.wait_for("message"), i want this to happen with a single message.
As an alternative to Łukasz Kwieciński's answer, you can also use *args to catch all arguments without a keyword as a tuple:
#client.command()
async def send_back(ctx, *sentence):
# sentence = ("whats", "upp!")
await ctx.send(" ".join(sentence))
For multi-word input use the keyword-only (*) argument
#client.command()
async def send_back(ctx, *, sentence):
await ctx.send(sentence)
Keyword-only arguments

Trying to make a Discord bot send a message that uses multiple randomly chosen words

I wanted to make a Discord bot with discord.py that sends a message made out of randomly chosen predetermined words. I've tried inserting another variable after the first one, but that just gave a syntax error. Here's my code by the way.
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('f!generate'):
variable1 = [
'test',
'test2',
'test3',]
variable2 = [
'test',
'test2',
'test3',]
await message.channel.send((random.choice(variable1)),(random.choice(variable2)))
How to fix the problem?
Messageable.send only takes 1 positional argument, you're passing 2. Simply add the two strings together and it should work
await message.channel.send(random.choice(variable1) + random.choice(variable2))

Checks For Reactions Discord.py

So I want to make a text game that edits the character every time the author who called the command reacts. My code so far for adding reactions:
#client.command()
async def test(ctx):
msg = await ctx.send('Hi')
up = '⬆'
down = '⬇'
left = '⬅'
right = '➡'
await msg.add_reaction(up)
await msg.add_reaction(down)
await msg.add_reaction(left)
await msg.add_reaction(right)
This adds the up arrow, down arrow, left arrow, and right arrow to the message "Hi". I want to see if someone clicked on the arrow and if that someone is the author of the command. I have no idea how to get if the author of the command clicked on the arrow reaction. Any help would be appreciated.
If you're waiting for a reaction, use wait_for() with the reaction_add event as the positional argument.
To limit it to the invoker, you can create a check and pass it into the check kwarg of wait_for(). The check would take in two arguments and you only need to compare if ctx.author is the same as the check author.
There is an example for wait_for() in the documentation
References: https://discordpy.readthedocs.io/en/latest/ext/commands/api.html?highlight=wait_for#discord.ext.commands.Bot.wait_for

Resources