I’m trying to make my first Discord Bot using typescript.
I made a simple dice roll command with a personal npm package, but there seems to be a problem with the Discord Slash command options.
I made a sum option that is NOT required, which sums any integer to the dice roll. But when I try to code that part, it returns these errors:
1-Argument of type 'string | number | boolean' is not assignable to parameter of type 'string'
2-Type 'number' is not assignable to type 'string'.ts(2345)
here is my code:
import { Command } from "../../structures/Command";
import { inlineCode } from "@discordjs/builders";
import aimless from "aimless";
export default new Command({
name: "roll",
description: "Rolls a dice.",
options: [
{
name: "dice",
description: "The dice you want to roll",
type: "STRING",
required: true
},
{
name: "sum",
description: "The sum you want to add to your roll(s)",
type: "INTEGER",
required: false
}
],
run: async({ interaction }) => {
const dice = interaction.options.get("dice").value;
const sum = interaction.options.get("sum");
console.log(sum)
let rolls;
try {
rolls = aimless.roll(dice);
} catch (e) {
return interaction.followUp(`**Invalid dice! n${inlineCode(e.toString().split(":")[2])}**`)
}
if (rolls.length == 1) {
if (!sum) {
return interaction.followUp(`**You rolled a ${inlineCode(rolls[0])}!**`);
} else {
return interaction.reply(`**You rolled a ${inlineCode(rolls[0])}!n ${inlineCode(rolls[0])} + ${inlineCode(sum.value)} = ${inlineCode(+rolls[0] + +sum.value)}.**`);
}
}
}
});
The errors are in this line at sum.value and +rolls[0] + +sum.value:
` return interaction.reply(`**You rolled a ${inlineCode(rolls[0])}!n ${inlineCode(rolls[0])} + ${inlineCode(sum.value)} = ${inlineCode(+rolls[0] + +sum.value)}.**`);`
I tried the same exact command in JavaScript with the @discordjs/builder “SlashCommandBuilder()” and it worked fine.
