#๐Ÿ”’ slash cmds

317 messages ยท Page 1 of 1 (latest)

barren crownBOT
#

@real snow

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.

real snow
#

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

lofty jungle
real snow
#

warning thr tho

#

wud u like to c that

lofty jungle
#

u sure and there isn't any error handler in your bot?

lofty jungle
real snow
#

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..

real snow
#

i think the last await shud be for response for that last warn ig

lofty jungle
#
await interaction.response.send(response=random_responses)

in here change the response=random_responses

#

to content = response

real snow
#

ah okah lemme c

lofty jungle
#

since send fucnction has no parameter response

real snow
#

lemme try

#

now

#

still app did not respond

lofty jungle
#

and the line doesn't make sense cuz above it you are doing

response = random.choice(random_response)```
real snow
#

i think i needa add somn after interaction part ? to make the bot sense that ppl r giving input ?

lofty jungle
#

oh and my bad

real snow
real snow
#

if am r8

lofty jungle
#

it's interaction.response.send_message()

real snow
#

oh

lofty jungle
#

not interaction.response.send()

real snow
#

retrying

#

hard luck

#

still app didnt respond

#

i can show u the ctx version

lofty jungle
#

can you send the current code

real snow
#

perhaps some changes over here ?

lofty jungle
#

and plz wrap it in codeblock

real snow
lofty jungle
#

!code

barren crownBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

real snow
#

here u go

lofty jungle
#

zzz

real snow
#

?

lofty jungle
#

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

real snow
#

so.. i put response=response over thr yea ?

lofty jungle
#

also ```py
async def magik(interaction:discord.Interaction):

type hint interaction parameter in your function definition
lofty jungle
real snow
#

this is slash for my ping cmd and it works fine

#

u can perhaps relate ?

lofty jungle
real snow
lofty jungle
#

it's wierd you are not getting errors

real snow
#

pycharm shit

#

lol

lofty jungle
#

perhaps you have an error handler?

real snow
#

to my surprise is tht
i got it to work
then it doesnt

#

lol

real snow
lofty jungle
real snow
#

but i dont this this is pretty much in our case

lofty jungle
#

those unrelated to our case

real snow
#

yea

#

then y it isnt working lol

lofty jungle
#

i'll check the command on my system

#

can you provide me the txt file

real snow
#

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

lofty jungle
#

๐Ÿชฆ

real snow
#

am so sorry for wasting ur time

#

it worked

#

now can i have a another help lol

lofty jungle
#

yeah keep on stating

real snow
#

sure my man

#

this is my current code

#

bot reply

#

but my question isnt shown

#

how do i do that

lofty jungle
#

what was your question?

real snow
#

i want a box to input questions

#

beside the slash

lofty jungle
#

do you want the option to be optional or compulsory

real snow
real snow
#

brb

lofty jungle
#

now your question will be the question

#

that you asked

real snow
#

what does str do ?

real snow
#

now i want the bot to display qesution

lofty jungle
#

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

real snow
#

gotcha

#

lemme try

#

i shud do this belowe with open thingy r8 ?

#

or below responsese

#

i put it below response and no change

lofty jungle
lofty jungle
real snow
#

got it done

#

thanls

#

how do i wrap it in an embed now

#

lol

#

last and final one

lofty jungle
#

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

real snow
#

oh

#

lol

#

nvm

#

tysm for ur time

#

appreciate it

lofty jungle
#

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

real snow
#

oh

#

also if ur wondering

#

i have alrdy done an embed in a cog

#

i just needa wrap this

lofty jungle
#

then it's the same

real snow
#

this is the test embed

real snow
#

lemme c

lofty jungle
#

you just need to make some slight modification to this structure

real snow
#

uhuh

lofty jungle
#

and you will be good to go

real snow
#

title be the questoin

#

description will b the answer

#

colour blah blah

#

and am done

#

lemme give it a shot

lofty jungle
#

this is what each part does and where it will be shown

real snow
#

uhuh

#

how do i make the title my question ??

lofty jungle
#

title = question

real snow
#

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

#

?

lofty jungle
#

how do you want it to look?

real snow
#

or else new idea

#

title shud be magik 8ball
also is anyway i can past link in this title ?

lofty jungle
#

yes there is a url parameter

real snow
#

description shud be
question
{user's question}

answer
{bot's answer)

real snow
lofty jungle
#

!d discord.Embed

barren crownBOT
#

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...
real snow
#

got it

#

now how do i add the question and answer part ?

#

title is magik 8ball

#

that i did

lofty jungle
#

!f-string

barren crownBOT
#
Format-strings

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.

real snow
#

okah

#

lemme c

#

do i put url link in " or ' ?

#

' i think ?

lofty jungle
#

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
real snow
#

got

#

have done somn

#

lemme c

#

moment of truth

#

phew

#

meh

#

i lost it

#

lesgooooooooooo

#

got it

#

slight mistake

#

where did the question go

lofty jungle
#

๐Ÿ‘

real snow
#

lol

#

trial and error is the key

#

lmao

lofty jungle
#

only error is the key incase of coding

real snow
#

lesgoooo

#

lemme make it bold

#

to leave 2 line

#

do i do \n two times ?

lofty jungle
#

\n\n

real snow
#

gotcha

#

moment of truth

#

purrfecto

#

just as i wanted

left lintel
#

can i make slash commands with multiple options with description

real snow
#

i think u add more stuff after interactions. part

#

also am not the best to help u out here

left lintel
lofty jungle
#
async def cmd(interaction:discord.Interaction, option_1:str, option_2:str): # Note that typehinting is important
left lintel
#

i want the full code that makes slash commands with multi options and options had description

left lintel
real snow
lofty jungle
real snow
#

@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

lofty jungle
#

there are multiple methods of adding in description

real snow
#

the one i did is also valid r8 ?

lofty jungle
#

yes

real snow
#

fine

#

@left lintel here u go

real snow
# lofty jungle yes

okah then dude
imma take off
thank you u so much for ur tym
really appreciate it

#

have a good day

real snow
#

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

lofty jungle
#

well if you do discord.app_commands then not needed

real snow
#

oh

#

the when is it needed ?

lofty jungle
#

and if u do app_commands only the you do

real snow
#

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

lofty jungle
#

idk can't tell without looking

#

where you are getting the error

real snow
#

oh

#

the place where tasks was the

real snow
#

i use it to change bots activity status

#

but it says unused tho

lofty jungle
#

yeah it's unused since it's darkened

real snow
#

but then error comes

#

y is that then ? any idea ?

lofty jungle
#

try running the code if it runs then no issue

#

except your linter

real snow
#

cuz red flag error

lofty jungle
real snow
#

where the task is thr

#

nvm

#

lol

#

lemme re run

real snow
#

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 ?

lofty jungle
#

there is no requirements.txt file in your project

real snow
#

thr is

#

and this is thr in tht

#

in this

lofty jungle
real snow
#

but i just showed u

lofty jungle
#

ignore it then ig

real snow
#

or can i delete the requirements file

#

and add it again

lofty jungle
#

you can try doing that idk

real snow
#

will it destroy my code tho ?

#

?

lofty jungle
real snow
#

good

#

lemme try

lofty jungle
#

it's just a file that tells what libraries you need for your project to work

real snow
#

still same warn

#

meh imma just ignore it ig

#

lol

#

nyways

#

thanks

#

!close

barren crownBOT
#
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.