#๐Ÿ”’ discord py buttons

152 messages ยท Page 1 of 1 (latest)

naive pilot
#

I can't access discord py server so i'll just ask here.
So, i created a uh view class and added 2 buttons, but only the second one appears on the message while the first doesn't, for some reason.

thorny quartzBOT
#

@naive pilot

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

undone plover
naive pilot
undone plover
naive pilot
#

also

naive pilot
undone plover
#

!paste

thorny quartzBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

naive pilot
#

also

#

i found a little mistake in the button thats not showing

#

i fixed it

#
@bot.tree.command(name="unravel", description="Play unraveling with someone.")
async def unravel(interaction: discord.Interaction, opp:discord.Member):
    await interaction.response.defer(thinking=True)
    view = unravelButtons(opp, interaction)
    if opp.bot:
        await interaction.response.send_message("You cannot play with a bot")
        return
    if opp.id in games["Players"] or interaction.user.id in games["Players"]:
        await interaction.response.send_message("You or your opponent are already playing a game.")
        return
    await interaction.followup.send('Asking the person if they want to play...')
    dmc = await opp.create_dm()
    await dmc.send(content=f"Yo <@{opp.id}>, <@{interaction.user.id}> wants to play with you, accept?", view=view)    

and now i get the error that the interaction cant be found (404)
in the first line of this command

undone plover
#

You need to give them different names

naive pilot
#

oh yeah

#

thanks

undone plover
naive pilot
#

sure

#

give me a moment

naive pilot
#

the error didnt happen again i guess

#

but the main issue is now solved

undone plover
naive pilot
undone plover
#

When you pass in a bot in opp

naive pilot
#

oh

#

no idea

#

let me try

undone plover
#

While using the command

#

Yeah

naive pilot
#

nope

#

doesnt seem like it

undone plover
#

Hm

naive pilot
#

i got a completely other error when i tried but not a error i cant solve

undone plover
naive pilot
#

i just did

undone plover
#

Oh

#

Well that solves it then

naive pilot
#

let me try the command fully

#

rq

undone plover
#

Alr

naive pilot
# undone plover Alr
Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/i686-linux-android/lib/python3.11/site-packages/discord/ui/view.py", line 430, in _scheduled_task
    await item.callback(interaction)
  File "<string>", line 38, in accept
  File "/data/user/0/ru.iiec.pydroid3/files/i686-linux-android/lib/python3.11/asyncio/tasks.py", line 442, in wait_for
    return await fut
           ^^^^^^^^^
  File "/data/user/0/ru.iiec.pydroid3/files/i686-linux-android/lib/python3.11/site-packages/discord/client.py", line 482, in dispatch
    result = condition(*args)
             ^^^^^^^^^^^^^^^^
TypeError: unravelButtons.accept.<locals>.check() missing 1 required positional argument: 'm'
#

thats

#

a weird error

#

or rather

#

thats the old code

#

ill create a new paste

#

oh i just realized

#

i gave you my bot token

undone plover
#

yeah lol

naive pilot
#

eh whatever

#

ill change it

#

so?

naive pilot
#

yes

undone plover
#

can you show your pip list

naive pilot
#

my

#

pip list?

undone plover
#

and perchance are you coding on andriod

undone plover
naive pilot
undone plover
#

it will show you the list of installed packages

undone plover
naive pilot
#
Package            Version
------------------ -----------
aiohttp            3.7.4.post0
android            1.0
astroid            2.15.8
async-timeout      3.0.1
attrs              23.2.0
audiostream        0.2
certifi            2024.2.2
cffi               1.16.0
chardet            4.0.0
charset-normalizer 3.3.2
cmake              3.26.4
dill               0.3.7
discord.py         2.4.0
distro             1.8.0
idna               3.6
isort              5.12.0
jedi               0.19.0
Kivy               2.2.1
lazy-object-proxy  0.0.0
mccabe             0.7.0
multidict          6.0.5
ninja              1.11.1
packaging          23.1
parso              0.8.3
pip                23.2.1
pkgconfig          1.5.5
platformdirs       3.10.0
pybind11           2.11.1
pycparser          2.21
pygame             2.5.0
pyjnius            1.5.0
pylint             2.17.5
PySDL2             0.9.15
requests           2.31.0
scikit-build       0.17.6
setuptools         68.2.2
six                1.16.0
tomlkit            0.12.1
typed-ast          1.5.5
typing_extensions  4.10.0
urllib3            2.2.1
wheel              0.41.2
wrapt              1.15.0
yarl               1.9.4
undone plover
#

discord bots can get very huge quickly and itll be very hard to manage on android

naive pilot
#

true

#

but

#

whats the solution to the error?

undone plover
#

hm

#

it seems like a library issue

naive pilot
#

how?

undone plover
#

and most probably due to you running it on android

naive pilot
#

hm

#

give me a moment

undone plover
#

its an OS issue

naive pilot
#

so

#

currently no solution?

undone plover
undone plover
#

pip uninstall discord.py and pip install discord.py

undone plover
#

the check you have defined

        def turncheck(self, m):
            return m.author.id == turn and m.channel.id == interaction.channel.id and len(m.content) == 4 and len(set(msg.content)) == 4

shoudln't take in self

#

in its parameter

#

if the function was defined as a class method it would take in self but youre defining it inside another method

naive pilot
#

my other 2 checks

#

they have self aswell

undone plover
#

and you should probably remove it in your other checks too

#

yeah

naive pilot
#

i'll try

undone plover
#

also i noticed you have an input statement in your on_ready

#

you should probably remove it

#

since input is blocking code and will block your bot's event loop from running and potentially causing it to send false reconnects and can ratelimit your bot

#

and on_ready can be fired multiple times too

naive pilot
#

i keep it when im still coding the bot

#

when its done i remove it and turn it into a command

#

also

#

the issue is solved

undone plover
#

cool

naive pilot
undone plover
#

yes?

naive pilot
#

soo

#

i can pass interaction in the view class right?

undone plover
#

yes you can

naive pilot
#

because the "opp" and interaction.user are the same in the buttons

#

the buttons are emant for the opponent

naive pilot
#

thats good

#

one more question

#

when i use the button

#

it does what its supposed to

#

but it keeps loading and eventually says this interaction failed

undone plover
#

can you show the code

naive pilot
#

how can i

#

i mean

#

its not really a issue

#

the code still works

undone plover
naive pilot
#

uh

#

i think both decline and accept

#

when i press the accept

#

it does it

#

haven't tested the decline one

#

but it probably does the same

undone plover
#

okay yeah fair enough

#

you arent responding to the interaction to both of them

naive pilot
#

im supposed to use interaction.response

#

?

undone plover
#

discord waits for 3 seconds by default to recive a response from your bot

undone plover
undone plover
#

and if you defer the interaction youll have to use followup

#

interaction.followup.send_message

naive pilot
#

its followup.send

#

but yes

undone plover
#

oh

#

okay

naive pilot
#

yeah

#

but anyways

#

thanks for the help again

#

guess ill use it somwhere

thorny quartzBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.