M
M
Maxim2021-09-20 00:26:56
Python
Maxim, 2021-09-20 00:26:56

How can I make it so that when a button is clicked, a message must be entered into the chat, and this message is recorded as a status in discord.py?

I want to make sure that when the button is clicked, the command to change the status is triggered, and the status changes to a message that the user writes to the chat. Sounds simple, but I can't figure it out. Help plz!

The code:

@bot.command(aliases=['profile', 'prof', 'p', 'account'])
async def _profile(ctx, member: discord.Member = None):
    if member is None:
        locale.setlocale(locale.LC_TIME, 'ru_RU')
        date_format = "%d %B %Y, %A"
        embed = discord.Embed(title=f"{person} Профиль ― {ctx.author}")
        embed.add_field(name="・ID:", value=f"``` {ctx.author.id}```")
        embed.add_field(name="・Репутация:", value=f"""``` {cursor.execute("SELECT rep FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]}```""")
        embed.add_field(name=f"・Статус:", value=f"""```{cursor.execute("SELECT rep FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]}```""", inline=False)
        embed.add_field(name='・Аккаунт создан:', value=f'``` {ctx.author.created_at.strftime(date_format)}```', inline=False)
        embed.add_field(name='・Присоединился:', value=f'``` {ctx.author.joined_at.strftime(date_format)}```')

        embed2 = discord.Embed(title=f"Изменить статус", description="Введите Ваш новый статус в чат.")

        em1 = bot.get_emoji(888910406674939965)     # ИЗМЕНИТЬ
        msg = await ctx.send(embed=embed,
                             components=[
                                 [
                                 Button(style=ButtonStyle.grey, id='1', label="Изменить статус", emoji=em1)
                                ]
                             ]
                             )

        response = await bot.wait_for("button_click")
        if response.channel == ctx.channel:
            if response.component.id == "1":
                await msg.edit(embed=embed2,
                                       components=[
                                           [
                                               Button(style=ButtonStyle.grey, id='2', label="Сбросить статус")
                                           ]
                                       ]
        response = await bot.wait_for("message")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TanderOFF, 2021-09-20
@D0ulink

It's easier to add a new !addstatus command and write the status to the database as text
. And in the !profile command, check if there is any value in the user_status column, if there is, before displaying it as you display the reputation value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question