#๐ slash cmds
317 messages ยท Page 1 of 1 (latest)
@real snow
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.
i want the bot to use slash commands and use the commad of magik to ask a question and reply random answer from 8ball responses.txt file
what the bot is doing
it shows application did not repsond
but it shows up in shlash cmds
any one care to help pls ?
also i want an input box beside the slash cmd where ppl can put the question inside that box
is there any error being printed in your terminal?
nop
lol
ikr
warning thr tho
wud u like to c that
u sure and there isn't any error handler in your bot?
yeah can you show it
i think the code is sumwhr inccorect
cuz i got it to work perfectly
now sumwhr somn is missing
no error thingy yet
am new
So..
sure
i think the last await shud be for response for that last warn ig
await interaction.response.send(response=random_responses)
in here change the response=random_responses
to content = response
ah okah lemme c
since send fucnction has no parameter response
oh
lemme try
now
still app did not respond
and the line doesn't make sense cuz above it you are doing
response = random.choice(random_response)```
i think i needa add somn after interaction part ? to make the bot sense that ppl r giving input ?
oh and my bad
umm okah so what do i do ?
?
that is to choose a random one from the file i think
if am r8
it's interaction.response.send_message()
oh
not interaction.response.send()
can you send the current code
and plz wrap it in codeblock
how do i do that ?
!code
here u go
zzz
?
you aren't sending any thing in here ```py
await interaction.response.send_message()
send_message is a function in which you need to pass the msg that you want to send
atm it's empty
so.. i put response=response over thr yea ?
also ```py
async def magik(interaction:discord.Interaction):
type hint interaction parameter in your function definition
content = response or just response since content is positional variable
didnt work
this is slash for my ping cmd and it works fine
u can perhaps relate ?
are you loading the magik command in a cog?
when i do this more errors r popping out lol
nop
it's wierd you are not getting errors
perhaps you have an error handler?
sadly not yet
to my surprise is tht
i got it to work
then it doesnt
lol
am getting warns tho
show em
those unrelated to our case
sure
wait a mun
i get t
lol
my txt file shit just disappeared the file is thr nothing is written over thr tho
that cud b the prblm
lemme put in somn and try
lol
how dumb
๐ชฆ
look dude
am so sorry for wasting ur time
it worked
now can i have a another help lol
yeah keep on stating
sure my man
this is my current code
bot reply
but my question isnt shown
how do i do that
what was your question?
do you want the option to be optional or compulsory
lucky?
which showing question ?
compulsroy
brb
then you need your function to take in a parameter and typehint as an str
Like
async def magik(interaction:discord.Interaction, question:str):
now your question will be the question
that you asked
got that done
now i want the bot to display qesution
then you can create a msg like
reply = f"**Q.** {question}?\n**Answer:**\n{response}"
``` and then send this reply
here question is the question parameter you created
and response is the answer
gotcha
lemme try
i shud do this belowe with open thingy r8 ?
or below responsese
i put it below response and no change
just before await interaction.response.send_message()
are you even sending it in send_message?
for that you will need to create a embed object
I suggest looking at a yt video
cuz verbally it will be hard to understand
yeah i don't mind telling you but it will be hard to understand what i'm telling you to do
so i suggest you watch a yt vid on how to create discord bot embeds
oh
also if ur wondering
i have alrdy done an embed in a cog
i just needa wrap this
then it's the same
this is the test embed
you just need to make some slight modification to this structure
uhuh
and you will be good to go
title be the questoin
description will b the answer
colour blah blah
and am done
lemme give it a shot
title = question
not like that
like the question from the user
how do i and quesiton from the user and answer from the bot whrvr i wanna place in the embed
that strcuture am not sure abt it
?
how do you want it to look?
or else new idea
title shud be magik 8ball
also is anyway i can past link in this title ?
yes there is a url parameter
description shud be
question
{user's question}
answer
{bot's answer)
cool
!d discord.Embed
class discord.Embed(*, colour=None, color=None, title=None, type='rich', url=None, description=None, timestamp=None)```
Represents a Discord embed.
len(x) Returns the total size of the embed. Useful for checking if itโs within the 6000 character limit.
bool(b) Returns whether the embed has any data set.
New in version 2.0.
x == y Checks if two embeds are equal.
New in version 2.0...
got it
now how do i add the question and answer part ?
title is magik 8ball
that i did
you will need to use f-string to format it however you want
!f-string
Creating a Python string with your variables using the + operator can be difficult to write and read. F-strings (format-strings) make it easy to insert values into a string. If you put an f in front of the first quote, you can then put Python expressions between curly braces in the string.
>>> snake = "pythons"
>>> number = 21
>>> f"There are {number * 2} {snake} on the plane."
"There are 42 pythons on the plane."
Note that even when you include an expression that isn't a string, like number * 2, Python will convert it to a string for you.
both will work
both single and double quotes represent strings in python
just remember both opening and ending quote should be same
you can't do it like
"this is a string' # this will give error
got
have done somn
lemme c
moment of truth
phew
meh
i lost it
lesgooooooooooo
got it
slight mistake
where did the question go
๐
only error is the key incase of coding
\n\n
can i make slash commands with multiple options with description
yes ofc
dank memer has it
i think u add more stuff after interactions. part
also am not the best to help u out here
give me a code
async def cmd(interaction:discord.Interaction, option_1:str, option_2:str): # Note that typehinting is important
i want the full code that makes slash commands with multi options and options had description
that is what he sent i think
options had no description
r u doing in a cog or not?
Discord.py allows for several ways to create/define application commands within itโs codebases. In this page weโll go through several of these.
@client.tree.command(name="ur command here", description="ur description here")
*if ur not doing in a cog **
@discord.app_commands.command(name="ur command name here", description="ur description here")
*if ur doing in a cog **
this is what i did
also make sure u have imported the required stuff
there are multiple methods of adding in description
oh
the one i did is also valid r8 ?
yes
okah then dude
imma take off
thank you u so much for ur tym
really appreciate it
have a good day
yo last thing
i dont needa import app_commands from discord seaparately now ?
cuz it says unused
evn tho in my cog i use app_commands for slash
well if you do discord.app_commands then not needed
and if u do app_commands only the you do
oh
okay cool
i removed it
also i got a task thing unused
but when i remove it it pops up an error
and says identifier expected
see that tasks
that is whr the error pops out
i use it to change bots activity status
but it says unused tho
yeah it's unused since it's darkened
then i can just remove it ?
but then error comes
y is that then ? any idea ?
i cant run
cuz red flag error
at which line
lol my bad
i removed tasks
but i didnt remove the comma b4 that
so thats y error
i removed comma
works fine
last and last thing for 2dy
phew
this thing is literally thr for every cogs and main python file
how do i resolve
but everything seems to work fine tho
sum dude told to ignore
but i dont like that yellow warning
so is thr anyway
to resolve this ?
there is no requirements.txt file in your project
but i just showed u
ignore it then ig
you can try doing that idk
nope
it's just a file that tells what libraries you need for your project to work
i deleted and tried
still same warn
meh imma just ignore it ig
lol
nyways
thanks
!close
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.