- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - 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!
#.addChoices is not a function
85 messages · Page 1 of 1 (latest)
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
Ok, thanks! I'll try right now.
That part worked, but i got a different problem. I got an error: Cannot read properties of undefined (reading 'guilds')
My motive was to get a server id and the bot will check on that server ID if a person has a specific role.
Use interaction.client, you don’t need that parameter (and probably don’t even pass it as it seems)
Another problem. That one worked but I want to get the role that the bot should check and the error is. Cannot read properties of undefined (reading 'roles')
Sorry for all of the problems, but I'm new to programming bots and yeah.
can you show your intents
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
"unknown guild" seems to indicate that the ID is incorrect
(or the bot isn't in that server maybe)
It wasn't in the server bruh
One sec.
I'll try again
Still the same, I'll paste again the guild ID.
you will also need to await on line 35, and on line 36 you probably want iffguild instead of guild
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.
ehm, you definitely need the quote marks on line 35
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
The guild doesn't work if it's a string
I put it as a number for now, but the cache is the problem.
it won't do what you think it does when you put it as a number
try logging the guild
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
How can i fix that?
Like i said above, I'm new to this so I don't know everything.
just use interaction.client, you don't need to explicitly pass a client
pretty much all djs structures have a client property
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
Can you write the script if that's not the problem for you?
The stuff that needs to be repaired.
The const thingy.
Ok i fixed the whole problem almost.
@lunar fjord
interaction.guild
.
Can someone explain to me how to get the .addChoices function because i tried everything but i wont see the function?
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
you have misplaced brackets. addChoices is a function on the option itself, not on the entire builder
where
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' }
)
)
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
what i said still applies
holy shit i see it know