maybebas
maybebas
DIAdiscord.js - Imagine an app
Created by maybebas on 11/25/2023 in #djs-questions
How do I check if a bot is in a voice channel?
I'm coding a music bot for my own use only and I would like to stop the bot joining a channel if another bot is currently in it. What could be the if statement?
4 replies
DIAdiscord.js - Imagine an app
Created by maybebas on 8/2/2023 in #djs-questions
How to get Interaction choice name? (djs v14.7.1)
Hi, I have an interaction with some choices. Every choice has a name and a value and I need both of them. I know how to get the value but how do I get the name?
module.exports = {
data: new SlashCommandBuilder()
.setName("loop")
.setDescription("description")
.addStringOption(option =>
option
.setName('type')
.setDescription('another description')
.setRequired(true)
.addChoices(
{name: `Off`, value: `0`},
{name: `Track`, value: `1`},
{name: `Queue`, value: `2`},
{name: `Autoplay`, value: `3`}
)),
module.exports = {
data: new SlashCommandBuilder()
.setName("loop")
.setDescription("description")
.addStringOption(option =>
option
.setName('type')
.setDescription('another description')
.setRequired(true)
.addChoices(
{name: `Off`, value: `0`},
{name: `Track`, value: `1`},
{name: `Queue`, value: `2`},
{name: `Autoplay`, value: `3`}
)),
let mode = interaction.options.getString('type')
//with this i get `0` if Off is selected, but how should I do to get `Off`?
let mode = interaction.options.getString('type')
//with this i get `0` if Off is selected, but how should I do to get `Off`?
3 replies
DIAdiscord.js - Imagine an app
Created by maybebas on 10/9/2022 in #djs-questions
Command handler error
Hi, I started coding this new bot with Typescript yesterday. I touched something and now my .ts file to deploy my commands won't work. The error doesn't happen in deploy_commands.ts actually but in my index.ts. Here's the code so far: deploy_commands.js
const fs = require('node:fs');
const path = require('node:path');
const { REST, Routes } = require('discord.js');
require("dotenv").config();

const commands : any[] = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
commands.push(command.data.toJSON());
}

const rest = new REST({ version: '10' }).setToken(process.env.CLIENT_TOKEN);

rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
const fs = require('node:fs');
const path = require('node:path');
const { REST, Routes } = require('discord.js');
require("dotenv").config();

const commands : any[] = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
commands.push(command.data.toJSON());
}

const rest = new REST({ version: '10' }).setToken(process.env.CLIENT_TOKEN);

rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
index.ts (interested part only)
client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
//The line above is 51
}
client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.ts'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
//The line above is 51
}
The error I get is as follows:
C:\mydir\index.ts:51
client.commands.set(command.data.name, command);
^
TypeError: Cannot read properties of undefined (reading 'name')
at Object.<anonymous> (C:\mydir\index.ts:51:35)
...
(I've reached max text)
C:\mydir\index.ts:51
client.commands.set(command.data.name, command);
^
TypeError: Cannot read properties of undefined (reading 'name')
at Object.<anonymous> (C:\mydir\index.ts:51:35)
...
(I've reached max text)
5 replies