#Subcommands for choices (if choices ==) please help

1 messages · Page 1 of 1 (latest)

harsh epoch
#

I need to take a base of subcommands but I need choices for a specific choice(e.g.)

#

/misccrate Tier 1 (tier1 choices)

#

Etc. Etc.

hollow flameBOT
#
interactions/subcmd.py

An example using subcommand groups and subcommands.

harsh epoch
#

Already was there

#

I have a specific case

#

I need to know what I have to fix here

#

Please.

rough tendon
#

If you can't see how you're wrong by comparing yuour code and the examples..

frozen ravine
#

Yea thats not how indentation works. just copy the examples and compare

harsh epoch
#

You mean

#

Ugh, sorry I just woke up

#

I was trying to do this the whole day yesterday

#

I need to take the first part as a blank

#

As a parent root command

#

Basically

@bot.slash_command()
async def misccrate(inter):
    pass```
drowsy falcon
#

Yeah, that part good

harsh epoch
#

Then the second part

#

As a subcommand, not group

drowsy falcon
#

Yeah

harsh epoch
#
@tier.sub_command()
async def tier(inter: #paste my code here)
     if choices == '1'
#

I feel like I have a mistake here

#

Inter is not going to be accessed, right?

drowsy falcon
#

It's not a subcommand of tier, but of misccreate

harsh epoch
#

Then what do I need to add?

drowsy falcon
#

Not add, but change

harsh epoch
#

I'm listening.

drowsy falcon
#

@<parent command name>.sub_command()

harsh epoch
#

Ohh

drowsy falcon
#

Your parent command is misccrate

harsh epoch
#

Okay okay

#

Here:

#
@misccrate.sub_command()
async def tier(inter:#paste my code here)
    if choices == '1':
      @tier.sub_command()
       async def cosmetics(inter: disnake.AppCmdInter, choices: str=commands.Param(name='cosmetics', choices=[#insert]
      if choices =#etc.
#

@drowsy falcon

#

Is this right?

frozen ravine
#

Why is it indented in the command itself.

#

Have you taken a look at the examples linked earlier?

harsh epoch
#

My question is is how to set it all properly

drowsy falcon
#

Why is there a subcommand of tier

frozen ravine
#

Look at the examples, there pretty good

harsh epoch
#

Oh okay

#

It's all supposed to be of 1 parent eh?

#

@drowsy falcon

#

I have a question here

#

if it's supposed to be like that or not

#

I need cosmetics choice to show up

rough tendon
#

It's like you're just ignoring literally everything you're being told

harsh epoch
#

Okay, tell me what I am missing

#

I may be stupid.

rough tendon
#

It's quite simple.

#

Look at your code.

#

Then look at

hollow flameBOT
#
interactions/subcmd.py

An example using subcommand groups and subcommands.

rough tendon
#

Find the differences and fix your code so that it matches

drowsy falcon
harsh epoch
#

on choice of 'Tier 1' e.g. I will get a list of the cosmetics inside of the tier 1

#
@bot.slash_command()
async def parent(inter):
    print("This code is ran every time any subcommand is invoked")


@parent.sub_command()
async def foo(inter, option: str):
    await inter.response.send_message(f"foo: {option}")


@parent.sub_command()
async def bar(inter, option: int):
    await inter.response.send_message(f"bar: {option}") 

This just gives me 2 commands

drowsy falcon
#

Then cosmetics is supposed to be the option choices of your tier subcommand

harsh epoch
#

@drowsy falconcosmetics not accessed

#

Ughghghghghhg

#

What is supposed to connect it to what?

#

it's the entire reason why I don't have cosmetics after tier

rough tendon
#

How many more times do you need to be told not to indent your sub command inside the parent command?

frozen ravine
#

I say, at-least 2 more

harsh epoch
frozen ravine
#

What are you calling a bitch? Your ignoring the help people are trying to provide and then wondering why its not working. This shouldn't be this much of an issue

harsh epoch
#

I'm really trying not to be aggressive

#

If for you it's so simple

frozen ravine
#

What is the expected behaviour? Do you want cosmetics to be called after the tier is called? What is the use case for the nesting in your eyes

harsh epoch
#

Then please understand that I have only 2 weeks of learning and I need a detailed help

frozen ravine
#

It's simple for you as well, don't nest it within the parent command. It could be as simple as copying the examples and renaming them

#

Like, just untab the cosmetics command and itll work

harsh epoch
frozen ravine
#

(Level being the @ bits)

rough tendon
#

It almost seems like they're trying to have a subcommand depending on which choice is selected.

#

If so, that's just not how it works.

harsh epoch
#

Whenever I choose the tier ('Tier 1' e.g.)

#

I want to see the next choices of that 'Tier 1'

rough tendon
#

Then you probably want autocomplete.

#

Not a sub command

harsh epoch
#

holy shit

frozen ravine
#

wdym 'next choices'. Like whats tier one?

harsh epoch
#

must

#

contain

#

ONE CONTENT.

frozen ravine
#

chill bro

harsh epoch
#

And the others other content.

frozen ravine
#

I also have zero context on what that means

#

So like,m extra arguments?

harsh epoch
#

/misccrate [Tier] (here we choose tier 1) [cosmetics] (here we have a list of cosmetics in tier 1)

rough tendon
#

Yeah, that sounds like autocomplete

hollow flameBOT
#
interactions/autocomplete.py

An example showcasing the two ways of adding autocompletion to slash command options.

rough tendon
#

And

harsh epoch
#

okay, how do I make that kind of autocomplete

rough tendon
#

-d ApplicationCommandInteraction.filled_options

remote zodiacBOT
rough tendon
#

Look at the example above

harsh epoch
#

it doesn't have the shit I need

rough tendon
#

Well duh. It's an example.

harsh epoch
#

I need someone to type this all out

frozen ravine
#

Atleast try yourself

#

Then we can help with what you tried

harsh epoch
#

HAH

#

I don't see the result.

frozen ravine
#

You've been trying autocomplete for two days?

harsh epoch
#

First I tried doing that through subcommands.

#

Now it turned out that I need autocomplete.

#

I wasted 5 hours on subcommands yesterday.

#

NOTHING IN RESULT.

frozen ravine
#

Uh huh, so your giving up?

harsh epoch
#

to write that shit out

frozen ravine
#

Can you at-least try?

harsh epoch
#

You think spending 2 days on something like this is funny enough?

#

I TRIED.

#

WDYM.

#

Am I doing something the internet has never done before????!?!?!?!?

frozen ravine
#

Okay, so send the autocomplete you tried please

#

Explain what you tried, what you wanted it to do and what it ended up doing

proper badgeBOT
#

Hey @harsh epoch!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
frozen ravine
harsh epoch
#

I'm trying to make this all

#

into my thing

#

async def autocomplete_langs(inter, string: str) -> List[str]:
    string = string.lower()
    return [lang for lang in LANGUAGES if string in lang.lower()]


@bot.slash_command()
async def languages_1(
    inter: disnake.CommandInteraction,
    language: str = commands.Param(autocomplete=autocomplete_langs),
):

@bot.slash_command()
async def languages_2(inter: disnake.CommandInteraction, language: str):
    ...


@languages_2.autocomplete("language")
async def language_autocomp(inter: disnake.CommandInteraction, string: str):
    string = string.lower()
    return [lang for lang in LANGUAGES if string in lang.lower()]
#

back to what we had

hollow flameBOT
#
interactions/autocomplete.py

An example showcasing the two ways of adding autocompletion to slash command options.

harsh epoch
#

@rough tendoncan you please at least help me and write this all down?

#

I'm trying my best not to be aggressive right now.

#

I really need this.

rough tendon
#

I see.

frozen ravine
#

Hmmm

#

yes

#

So firstly, I think we work on fixing your command so its not indented in the other

frozen ravine
#

Or given you don't need a subcommand, we can delete it for now

rough tendon
#

save it and share the link.

harsh epoch
drowsy falcon
harsh epoch
#

Mentally

drowsy falcon
#

Why did you create a cosmetics subcommand

#

I thought cosmetics are supposed to be option choices for a tier subcommand

frozen ravine
#

So lets consider this code:

@bot.slash_command()
async def misccrate(inter):
     pass

@tier.sub_command()
async def tier(inter: disnake.AppCmdInter, choices: str=commands.Param(name='crate', choices=['Tier 1', 'Tier 2', 'Tier 3'])):
    if option == 'Anders Army':
        embed = disnake.Embed(title='Anders Army', description='Tier: GENERAL', url='', color=0x008000)
        embed.set_image(url='https://static.wikia.nocookie.net/arms-of-solitaire/images/8/83/Anders_Army.png/revision/latest?cb=20230408150639')
        embed.set_footer(text='Official YLWB Bot.')
        await inter.response.send_message(embed=embed)
        
#

This is the code we are going to use going forward

#

Lets define another option option

#
@tier.sub_command()
async def tier(inter: disnake.AppCmdInter, choices: str=commands.Param(name='crate', choices=['Tier 1', 'Tier 2', 'Tier 3']), option: str):
    ...

@tier.autocomplete("option")
async def autocomp(inter: disnake.CommandInteraction, string: str, choices: str):
    if choices == "Tier 1":
      return [choices for tier one]

    return [...]

Now I dont actually know if this is how cross param auto complte works in disnake. Its how it works in NC so you will need to test it and see if you can get the params passed this way

#

I'll look into it now, but for the meantime thats my guess

rough tendon
#

you can user inter.filled_options

frozen ravine
#

Ooo, okay. Use that ^

#

I know nextcord lets you ask for other arguments from the parent command in autocomplete but unsure of disnake off the top of my head

rough tendon
#

You can do that in disnake, too. But they must be kwargs, IIRC

frozen ravine
#

Im sure teacup can 'try it and see' for us ; )

drowsy falcon
#

From the yesterday's context this isn't actually doing what he wants

harsh epoch
rough tendon
#

Otherwise, you can use filled_options and do like choice = inter.filled_options.get('choices') or whatever the first arg is called.

frozen ravine
harsh epoch
#

I'm making this wikibot for a community.

#

And the command is related to the crates containing cosmetics.

#

Tier 1 must contain Anders Army for example.

frozen ravine
harsh epoch
#

And I need to choose the tier of the crate first, let's write it down:

#

/misccrate [Tier 1]

#

In tier 1 we have Anders Army, Sir Shauter, etc.

#

But we want to test this on Anders Army.

#

/misccrate [Tier 1] [Anders Army] (the result is supposed to be our embed)

drowsy falcon
# frozen ravine Please do expand if you have more context

They want a command where you have two selectable "parameters" to fill, where the second one's options are dictated by the first one

It's not doable with two static option choice parameters, thus Sharp suggested making the first parameter into separate subcommands, where each subcommand would provide the "second" option independently of other subcommands

#

The other way would be to use autocomplete but seeing how they struggled with basic bits we put that off the reach

frozen ravine
#

Yea, we are suggesting autocomplete using the first option

harsh epoch
frozen ravine
#

Paste please

#

Screenshots dont let us work with it as easily

harsh epoch
#
@bot.slash_command()
async def misccrate(inter):
     pass

@tier.sub_command()
async def tier(inter: disnake.AppCmdInter, choices: str=commands.Param(name='crate', choices=['Tier 1', 'Tier 2', 'Tier 3'])):
    if option == 'Anders Army':
        embed = disnake.Embed(title='Anders Army', description='Tier: GENERAL', url='', color=0x008000)
        embed.set_image(url='https://static.wikia.nocookie.net/arms-of-solitaire/images/8/83/Anders_Army.png/revision/latest?cb=20230408150639')
        embed.set_footer(text='Official YLWB Bot.')
        await inter.response.send_message(embed=embed)
        
@tier.sub_command()
async def tier(inter: disnake.AppCmdInter, choices: str=commands.Param(name='crate', choices=['Tier 1', 'Tier 2', 'Tier 3']), option: str):
    ...

@tier.autocomplete("option")
async def autocomp(inter: disnake.CommandInteraction, string: str, choices: str):
    if choices == "Tier 1":
      return [choices for 'Tier 1']

    return [...]
#

I don't know why it shows so many errors

#

tier and option are not defined

rough tendon
#

Well that's becuase you're trying to set tier as a subcommand of tier, and you didn't define option anywhere.

harsh epoch
#

set tier as a subcommand of tier.

#

Hm.

hollow flameBOT
#
interactions/autocomplete.py

An example showcasing the two ways of adding autocompletion to slash command options.

harsh epoch
#

Omg, for God Sake

#

why is this so hard

rough tendon
#

It's not.

#

Pay attention to the examples

harsh epoch
#

Can you help please?

drowsy falcon
#

What has he been doing the whole time

harsh epoch
#

The @hollow flame example shows something that is a complete opposite of my request.

rough tendon
#

Well it's not going to tell you how to fix the errors you're having.

#

But you CAN use it to understand how to implement the feature you're after, then replicate it using your own arguments and commands

harsh epoch
#

Please.

rough tendon
harsh epoch
#

@rough tendon how do I properly explain my request to ChatGPT?

frozen ravine
#

I'll be honest here, I'd recommend learning some more Python. Disnake is not exactly beginner friendly and you should be able to understand the help we are providing. This indicates to me at-least you are reliant on sources such as ChatGPT which are going to be widley incorrect and while might give you the general gist, you still need to understand enough to fix it yourself, which I feel you don't have as your asking us to simply write it for you as the help we are providing is being misunderstood.

I'm happy to provide some resources for learning more Python, specifically related to the things applicable here but I feel like further help from at-least myself is simply going to miss the mark as your relying on outside resources without an understanding yourself and its leading to a communication differences between us (le helpers) and yourself.

Don't get me wrong, we all do want to help. Like, we really do. But theres a point where learning a bit more about the language your trying to write will also be beneficial to you

harsh epoch
#

Please write a slash command for discord bot using disnake library. The first option must be called tier. In option tier we will have 3 choices: Tier 1, Tier 2, Tier 3. All of them must contain their own content for the second option called cosmetics.
For example, if we choose Tier 1, in the second option we will have choices "Anders Army" and "Sir Shauter".
If we choose Tier 2, in the second option we will have choices "Perestroyka" and "Paris Night".
If we choose Tier 3, in the second option we will have choices "Tankist Hat" and "Sky Baron".
When we choose the second option, I want to get a text and image in the embed with the title and description.

#

I think this should do

frozen ravine
#

ChatGPT also likely wont have the data required to help you here. This implementation is too new for it to likely have been trained on it

#

(To be real)

harsh epoch
#

@frozen ravine

#
@bot.slash_command()
async def tier(inter):
    tier_choices = ['Tier 1', 'Tier 2', 'Tier 3']
    cosmetics_mapping = {
        'Tier 1': ['And Army', 'Sir Shauter'],
        'Tier 2': ['Perestroyka', 'Paris Night'],
        'Tier 3': ['Tankist Hat', 'Sky Baron']
    }

    tier_option = disnake.OptionChoice(name='tier', description='Tier', choices=tier_choices, required=True)
    cosmetics_option = disnake.OptionChoice(name='cosmetics', description='Cosmetics', choices=[])

    inter_option(tier_option)
    inter.add_option(cosmetics_option)

    selected_tier = inter.get_option('tier')
    selected_cosmetics = inter.get_option('cosmetics')

    if selected_tier in tier_choices and selected_cosmetics in cosmetics_mapping[selected_tier]:
        embed_title = selected_cosmetics
        embed_description = f": {selected_tier}"

        embed = disnake.Embed(title=embed_title, description=embed_description, color=0x008000)
        embed.set_footer(text='Official YLWB Bot.')

        # Set the image based on the selected options
        if selected_cosmetics == 'Anders Army':
            embed.set_image(url='https://static.wikia.nocookie.net/arms-of-solitaire/images/883/Anders_Army.png/revision/latest?cb=20230408150639')
        elif selected_cosmetics == 'Sir Shauter':
            embed.set_image(url='[URL_TO_SIR_SHAUTER_IMAGE]')
        elif selected_cosmetics == 'Perestroyka':
            embed.set_image(url='[URL_TO_PERESTROYKA_IMAGE]')
        elif selected_cosmetics == 'Paris Night':
            embed.set_image='[URL_TO_PARIS_NIGHT_IMAGE]')
        elif selected_cosmetics == 'Tankist Hat':
            embed.set_image(url='[URL_TO_TANKIST_HAT_IMAGE]')
        elif selected_cosmetics == 'Sky Baron':
            embed.set_image(url='[URL_TO_SKY_BARON_IMAGE]')

        await inter.response.send_message(embed=embed)

    else:
        await inter.response.send_message("Invalid options selected.")```
#

AI generated

rough tendon
#

No.

drowsy falcon
harsh epoch
#

I'm trying to fix them

drowsy falcon
#

Have fun 👍

harsh epoch
#

I need to tell it that.

#

There must be choices in like brackets

#

whenever you do the slash commands you have options

#

it lacks them

harsh epoch
#

@rough tendon

#

chatgpt is struggling with this

harsh epoch
#

@drowsy falcon BRO NOT EVEN CHATGPT CAN SOLVE IT PROPERLY

#

AM I REALLY DOING SOMETHING IMPOSSIBLE

regal crypt
#

no, you're not.

regal crypt
#

You're extremely prone to ignoring what we say mmlolbutbadlydrawn

harsh epoch
#

FUCK THIS

#

I GIVE UP

#

@regal crypt

#

If AI can't, no one can

#

especially me

drowsy falcon
#

You're overestimating the "AI"

regal crypt
drowsy falcon
#

I mean this is truly a difficult task of describing to a computer what you want it to do for you

harsh epoch
#

Because I can't and I am asking for help.

regal crypt
drowsy falcon
#

Pay catsip

regal crypt
#

we're here to help you figure out how to do it, not to write your code for you

harsh epoch
#

Is it so hard for you to fix a few lines????

#

Holy shit.

regal crypt
#

skill issue?

harsh epoch
#

Helping issue?

drowsy falcon
#

Don't blame us for your problems

harsh epoch
#

The only choice for me is to ask someone for it.

#

If I am left with nothing but to think with "the patience".

regal crypt
#

I have no qualms writing some code for someone who can't figure it out but is willing to learn. I do not get that notion from you whatsoever

harsh epoch
#

Whatever then.

drowsy falcon
#

Like 5 people dedicated their time to helping you, to no avail

regal crypt
harsh epoch
#

Ethan did something at the very least.

regal crypt
#

this is not an us issue whatsoever

drowsy falcon
harsh epoch
#

And then, there are no guides on what I need specifically.

regal crypt
#

because you don't need them

harsh epoch
#

I actually feel like that someone did it and doesn't want to share the "formula".

regal crypt
#

it's a simple as combining two basic things

harsh epoch
#

I scrolled down a million times.

regal crypt
#

really not getting through, am I

harsh epoch
#

I tried searching up on stacks overflow.

harsh epoch
#

This and that?

regal crypt
#

hmm, let me go back to what I sent yesterday

#

voila, #help-other message:

as in, main command misccrate with subcommands crate1, crate2 and crate3; with one parameter with choices each

Discord

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

harsh epoch
#

Here I am sitting and trying to do something out of spite.

regal crypt
#

that still isn't how you do subcommands

#

you don't define a command inside another command

harsh epoch
#

I'm just plain tired of it

#

It's day 2 of trying this

hollow flameBOT
#
interactions/subcmd.py

An example using subcommand groups and subcommands.

harsh epoch
#

bruh............................

regal crypt
#

that is by far the easiest way of achieving close to what you want

#

you'd make three commands, /crates tier1, /crates tier2 and /crates tier3

#

now, you should already know how to add a param with options to each of those

#

and you're done

harsh epoch
#

Well, wait

#

actual shit

drowsy falcon
#

Saying you're tired won't get someone else to do it for you
At least not here

harsh epoch
#

@drowsy falcon

#

what's supposed to be in await in my case

drowsy falcon
#

What is supposed to happen at that point?

harsh epoch
regal crypt
#

that was a genuine question as you can do multiple things and they can't read your mind

harsh epoch
#

question

#

how do I make option have

#

autocomplete

#

aka list

regal crypt
#

you had that figured out yesterday, no?

harsh epoch
#

no

#

yesterday I had a headache.

regal crypt
#

option_name: str = commands.Param(choices=...)

harsh epoch
#

In the evening.

#

alright thanks

harsh epoch
#

what?

#

huh

regal crypt
#

show your code rq

harsh epoch
#

I added the option_name str = commands.Param(choices=...)

#

Option in our case

#

is 'cosmetic'

drowsy falcon
#

Choices is a list

regal crypt
#

choices should be a list

harsh epoch
#

choices=list[

#

Next I forgot what comes after list

regal crypt
#

that's not how you make lists

harsh epoch
#

do I have to make them

#

uh

#

outside the command?

regal crypt
#

no, you don't

#

how would you make a list containing "foo" and "bar"?

harsh epoch
regal crypt
#

there you go

#

now you just do choices=[...]

harsh epoch
#

Okay, it works

#

tysm

hollow flameBOT
#
Solved!

Marked the thread as solved. If your question has not been answered, please open a new thread in #1019642966526140566.