#.addChoices is not a function

85 messages · Page 1 of 1 (latest)

agile quailBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
daring birch
#

Yes, there are no custom choices on a RoleOption. It’ll show all roles from that guild. If you want choices you need a StringOption

karmic coral
#

Ok, thanks! I'll try right now.

karmic coral
daring birch
#

Use interaction.client, you don’t need that parameter (and probably don’t even pass it as it seems)

karmic coral
#

Ok.

#

On sec.

#

one*

karmic coral
#

Sorry for all of the problems, but I'm new to programming bots and yeah.

lunar fjord
#

can you show your intents

karmic coral
#

yup sure

#

@lunar fjord

lunar fjord
#

ok, that seems fine. can you try fetching the guild instead of retrieving from the cache? at least that will throw an error if the guild ID is invalid

karmic coral
#

ok

#

One sec.

#

2 errors

#

@lunar fjord

lunar fjord
#

"unknown guild" seems to indicate that the ID is incorrect

#

(or the bot isn't in that server maybe)

karmic coral
#

It wasn't in the server bruh

#

One sec.

#

I'll try again

#

Still the same, I'll paste again the guild ID.

lunar fjord
#

you will also need to await on line 35, and on line 36 you probably want iffguild instead of guild

karmic coral
#

ok

#

Now only 1 error, unknown guild. @lunar fjord

#

Ok i changed without the comma

#

And it's good

#

but next problem

#

@lunar fjord

#

Im going to try do this by role ID.

#

One sec.

#

Still the same error.

lunar fjord
#

ehm, you definitely need the quote marks on line 35

karmic coral
#

There are quote marks.

lunar fjord
#

the long string of numbers

#

that should be a string

#

not a number

#

if it doesn't work when you make it a string, then there's another issue

karmic coral
#

I put it as a number for now, but the cache is the problem.

lunar fjord
#

it won't do what you think it does when you put it as a number

#

try logging the guild

karmic coral
#

@lunar fjord

#

I don't know if I did the logging correct, but yeah.

lunar fjord
#

i suppose that works... but it seems like you aren't passing guilds and client to the function

#

anyway you don't need to, just use interaction.client

karmic coral
#

Like i said above, I'm new to this so I don't know everything.

lunar fjord
#

just use interaction.client, you don't need to explicitly pass a client

#

pretty much all djs structures have a client property

karmic coral
#

Ok

#

Next problem.

#

Cannot read properties of undefined (reading 'roles')

lunar fjord
#

you didn't fix the guild ID to be a string, and you aren't referencing the guild variable anymore. <Client>.guild isn't a thing

#

by the way you don't need to deploy your commands each time, unless the command structure changes

#

if you do that you'll get rate limited

karmic coral
#

The stuff that needs to be repaired.

#

The const thingy.

#

Ok i fixed the whole problem almost.

#

@lunar fjord

surreal brook
karmic coral
#

Tysm

#

The problem has been solved

karmic coral
#

.

silent vortex
#

Can someone explain to me how to get the .addChoices function because i tried everything but i wont see the function?

silent vortex
# lunar fjord can you show your code
const fs = require('fs').promises;
const { Rcon } = require('rcon-client');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('addplayer')
        .setDescription('Replies with Pong!')
        .addStringOption(option => 
            option.setName('name')
                .setDescription('The name of the player')
                .setRequired(true))
        .addStringOption(option => 
            option.setName('dimension')
                .setDescription('Set the dimension in wich you spawn the player in')
                .setRequired(true))
                .addChoices(
                    { name: 'Overworld', value: 'overworld' },
                    { name: 'Nether', value: 'the_nether' },
                    { name: 'The End', value: 'the_end' }
                )```
#
                 ^

TypeError: (intermediate value).setName(...).setDescription(...).addStringOption(...).addStringOption(...).addChoices is not a function
    at Object.<anonymous> (C:\Users\Gebruiker\Desktop\1.21 server MC\Nieuwe Chatbot\commands\database\spawnPlayer.js:17:18)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1137:19)
    at require (node:internal/modules/helpers:121:18)
    at Object.<anonymous> (C:\Users\Gebruiker\Desktop\1.21 server MC\Nieuwe Chatbot\reloadCommands.js:15:19)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)```
#

const { SlashCommandBuilder } = require('@discordjs/builders'); i tried this also

#

and that didnt work either

lunar fjord
#

you have misplaced brackets. addChoices is a function on the option itself, not on the entire builder

silent vortex
#

where

lunar fjord
#

you probably want this

new SlashCommandBuilder()
        .setName('addplayer')
        .setDescription('Replies with Pong!')
        .addStringOption(option => 
            option.setName('name')
                .setDescription('The name of the player')
                .setRequired(true))
        .addStringOption(option => 
            option.setName('dimension')
                .setDescription('Set the dimension in wich you spawn the player in')
                .setRequired(true)
                .addChoices(
                    { name: 'Overworld', value: 'overworld' },
                    { name: 'Nether', value: 'the_nether' },
                    { name: 'The End', value: 'the_end' }
                )
        )
silent vortex
#
const fs = require('fs').promises;
const { Rcon } = require('rcon-client');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('addplayer')
        .setDescription('Replies with Pong!')
        .addStringOption(option => 
            option.setName('name')
                .setDescription('The name of the player')
                .setRequired(true))
        .addStringOption(option => 
            option.setName('dimension')
                .setDescription('Set the dimension in wich you spawn the player in')
                .setRequired(true))
                .addChoices(
                    { name: 'Overworld', value: 'overworld' },
                    { name: 'Nether', value: 'the_nether' },
                    { name: 'The End', value: 'the_end' }
                )
        .addStringOption(option => 
            option.setName('x')
                .setDescription('X cordinate')
                .setRequired(true))
        .addStringOption(option => 
            option.setName('y')
                .setDescription('Y cordinate')
                .setRequired(true))
        .addStringOption(option => 
            option.setName('z')
                .setDescription('Z cordinate')
                .setRequired(true)),       
    async execute(interaction) {
        if (interaction.channel.id == `1257338710161096756`) {
            const name = interaction.options.getString('name');
            const xCor = interaction.options.getString('x');
            const yCor = interaction.options.getString('y');
            const zCor = interaction.options.getString('z');
            const dimensionSpawn = interaction.options.getString('dimension')

            const host = 'localhost'
            const port = '25575'
            const password = 'djflaskfklefalkdfj'
            const chatChannel = '978000323731935332'

            let rcon
            rcon = new Rcon({ host, port, password });
            console.assert(typeof host === 'string', 'Must be a string')
            try{
                await rcon.connect()
                try{
                    rcon.send(
                        `execute in minecraft:${dimensionSpawn} run player ${name} spawn at ${xCor} ${yCor} ${zCor}`
                    )
                } catch {
                    console.log('Sending Failed!!')
                }
                rcon.end()

                try {
                    await interaction.reply({ content: `Added ${name} to the server at ${xCor}  ${yCor}  ${zCor}`, ephemeral: true });
                } catch (err) {
                    await interaction.reply({ content: 'Error', ephemeral: true });
                }
            } catch (error) {
                interaction.reply({ content: `Minecraft server is offline!`, ephemeral: true })
            }
        } else {
            interaction.reply({ content: `Wrong channel mf!`, ephemeral: true })
        }
    },
};```
#

this is the ful thing

lunar fjord
#

what i said still applies

silent vortex
#

holy shit i see it know