Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accept user input in an embedded message Discord.py

I was wondering how I would be able to accept user input from an embedded message like this image does: enter image description here

Doesn't have to be exactly like that, but I want a guild member to be able to input information into an embedded message. I haven't been able to find anything about it in Discord.py API

like image 587
yet-it-compiles Avatar asked Oct 20 '25 04:10

yet-it-compiles


2 Answers

The image shown is embedded message which does not take input but shows the output after taking input from a user as a text form. You can use the code given below:

@bot.event()
async def on_message(message):
  if message.author==bot.user: 
    return

  msg = message.content

  if msg.startswith("!cal "):
    names = msg.split("!cal ",1)[1]
    data = names.split("*")
    a = data[0]
    b = data[1]
    c=int(a)*int(b)
    r=str(c)
    em=discord.Embed(title=f"Calculator",description=f"Input\n```{a}*{b}```\n\nOutput\n```{r}```")
    await message.channel.send(embed=em)

You can use this code to show the same result. NOTE : User must enter the command properly as !cal 5*5

like image 87
Siddhant Chauhan Avatar answered Oct 23 '25 05:10

Siddhant Chauhan


In the Discord API there's no way to accept an user input, but you can do something like this:

ctx.send(embed=discord.Embed(title="Hey", description="Tell me something!"))
msg = Bot.wait_for("message")
ctx.send(embed=discord.Embed(title="You said...", description=msg.content)

If you want some information from the user who used the command, try this:

while True:
    msg = Bot.wait_for("message")
    if (msg.author == ctx.author):
        break

Then, you may like to do something like this:

# Same stuff as before...
result = eval(msg.content)
ctx.send(embed=discord.Embed(title="Result", description=result))

This will work like the calculator you shown in the answer.

like image 42
FLAK-ZOSO Avatar answered Oct 23 '25 03:10

FLAK-ZOSO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!