#๐ discord py buttons
152 messages ยท Page 1 of 1 (latest)
@naive pilot
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.
@naive pilot
well the codes too big to send
Send only the view
also
thats what im doing
!paste
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.
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
The name of both the methods are the same so the second one will overwrite the first one
You need to give them different names
what about this?
Can you show the entire traceback
well
the error didnt happen again i guess
but the main issue is now solved
Does it happen when you ping a bot
when i ping a bot?
When you pass in a bot in opp
Hm
like i said the error happend at the first line of the command
i got a completely other error when i tried but not a error i cant solve
Just in case replace interaction.response.send_message with interaction.followup.send in the if statements
i just did
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
the code is in https://paste.pythondiscord.com/J5IA
or rather
thats the old code
ill create a new paste
oh i just realized
i gave you my bot token
yeah lol
is this the entire error?
yes
can you show your pip list
and perchance are you coding on andriod
run pip list in your terminal
yes
it will show you the list of installed packages
well if you have a pc/laptop you should definetly use that
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
vacation
discord bots can get very huge quickly and itll be very hard to manage on android
how?
and most probably due to you running it on android
its an OS issue
the traceback roots to the library instead of your code
try reinstalling discord.py
pip uninstall discord.py and pip install discord.py
ohh wait i think i get it
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
well
my other 2 checks
they have self aswell
i'll try
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
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
cool
i have 2 questions
yes?
yes you can
because the "opp" and interaction.user are the same in the buttons
the buttons are emant for the opponent
alright
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
can you show the code
i suppose you mean the decline button right?
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
discord waits for 3 seconds by default to recive a response from your bot
yes
so
if i use defer
and if you defer the interaction youll have to use followup
interaction.followup.send_message
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.