Help with Typescript #1519
-
I don't know why I do this to myself, but decided to give Typescript a go and update the code accordingly. Sadly, some things that work on Javascript, Typescript starts complaining about, even when it looks like they should work, but I'm probably missing some basic stuff. I'm having this issue first. When crating a message with components, this error comes up. CLIENT.on(Events.MessageCreate, async (interaction) => {
if (interaction.author.bot) {
return;
}
if (interaction.content.toLowerCase() === "!games") {
const ROW = new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId("game_mode")
.setPlaceholder("Select a Game Mode")
.setMinValues(1)
.setMaxValues(1)
.addOptions([
{
label: "Option 1",
description: "This is a description",
value: "first_option"
},
{
label: "Option 2",
description: "This is also a description",
value: "second_option"
}
])
);
await interaction.reply({ content: "GAME MODES", components: [ROW] });
}
}); The error in on
Not so familiar with Typescript so not sure what the solution would be here. Also, another error I get is that: CLIENT.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isCommand()) {
return;
}
if (interaction.commandName === "gw") {
const ROUNDS = interaction.options.getInteger("rounds", false) || 5;
await interaction.reply("Not implemented!");
return;
}
}); In this case the error is on
I'm guess in both cases I'm missing some Any help or guidance in the right direction appreciated. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Welcome to TypeScript!
Your second issue is TypeScript protecting you. |
Beta Was this translation helpful? Give feedback.
Welcome to TypeScript!
ActionRowBuilder
must have a generic that specifies what kind of components it holds. See the guide.Your second issue is TypeScript protecting you.
isCommand()
only allows context menu command interactions and chat input command interactions through. However, context menu command interactions do not have a.getInteger()
method. In the case your client receives such an interaction, it will crash. If you only want to allow chat input command interactions through, useisChatInputCommand()
instead.