Ori
Ori
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Ori on 1/3/2024 in #djs-voice
Send audio from one channel to another one in another guild
Hi, I'm currently making a discord bot about game events utilities, and I had an idea. Basically I want to create a command to make the bot join a voice channel, and mirror the audio to another voice channel. Is this possible? And if yes, is there some basic documentation about this sort of thing?
2 replies
DIAdiscord.js - Imagine an app
Created by Ori on 11/25/2023 in #djs-questions
Delete slash command if it is "forgotten"
I have a problem with my guilds slash commands where If I delete a command in my code, it stays in the guild. Now I'm trying to code something to delete the slash command if it doesn't "exist" anymore in the code, but I'm getting an error. Here's my output:
❯ npm start

> node scripts/start.js && npm run build && cd dist && node src/index.js


> rimraf dist/* && tsc && tsc-alias && tscp

Non-typescript files copied
discord-dev-env
✓ Created logs folder at: /Users/marlon/Javascript/discord-dev-env/dist/logs
✓ Logged in as xxx#0000!
ℹ Initalizing Events...
✓ Events have been loaded! [interactionCreate.js]
ℹ Started deploying slash commands...
✓ Cleared global commands cache!
ℹ Scanning commands in "/Users/marlon/Javascript/discord-dev-env/dist/src/commands"
✓ (/) Reloaded guild-specific commands for 0 guilds.
✓ (/) Reloaded 3 global commands
✓ All slash commands have been deployed. The bot is ready to run!
✖ An error occured while deleting left-over command:
DiscordAPIError[10063]: Unknown application command
❯ npm start

> node scripts/start.js && npm run build && cd dist && node src/index.js


> rimraf dist/* && tsc && tsc-alias && tscp

Non-typescript files copied
discord-dev-env
✓ Created logs folder at: /Users/marlon/Javascript/discord-dev-env/dist/logs
✓ Logged in as xxx#0000!
ℹ Initalizing Events...
✓ Events have been loaded! [interactionCreate.js]
ℹ Started deploying slash commands...
✓ Cleared global commands cache!
ℹ Scanning commands in "/Users/marlon/Javascript/discord-dev-env/dist/src/commands"
✓ (/) Reloaded guild-specific commands for 0 guilds.
✓ (/) Reloaded 3 global commands
✓ All slash commands have been deployed. The bot is ready to run!
✖ An error occured while deleting left-over command:
DiscordAPIError[10063]: Unknown application command
The code to delete the slash command is the following:
const command = interaction.client.commands.get(interaction.commandName)
if (!command) {
const rest = new REST().setToken(process.env.token)
try {
rest.delete(Routes.applicationGuildCommand(process.env.clientId,interaction.guild.id,interaction.id))
.then(()=> logging(`Deleted leftover command ${interaction.commandName} in guild "${interaction.guild.id}`,"minimal"))
.catch(err => logging(`An error occured while deleting left-over command:\n${err}`,"error"))
} catch (error) {
logging("An error occured while deleting left-over command:\n" + error,"error")
}
interaction.reply({content: "Command is outdated. It cannot be used anymore."})

return
}
const command = interaction.client.commands.get(interaction.commandName)
if (!command) {
const rest = new REST().setToken(process.env.token)
try {
rest.delete(Routes.applicationGuildCommand(process.env.clientId,interaction.guild.id,interaction.id))
.then(()=> logging(`Deleted leftover command ${interaction.commandName} in guild "${interaction.guild.id}`,"minimal"))
.catch(err => logging(`An error occured while deleting left-over command:\n${err}`,"error"))
} catch (error) {
logging("An error occured while deleting left-over command:\n" + error,"error")
}
interaction.reply({content: "Command is outdated. It cannot be used anymore."})

return
}
Can't I use the command interaction ID to delete it?
50 replies
DIAdiscord.js - Imagine an app
Created by Ori on 11/12/2023 in #djs-questions
Build Error with ts-node
Hi, I'm using typescript and I'm getting a strange error that isn't actually in my file!
Error:
Failed to import from:
/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/commands/alerts/alerts.ts.
Options:
{}
Require error message:
TSError: ⨯ Unable to compile TypeScript:
src/commands/alerts/functions.ts:2:32 - error TS2532: Object is possibly 'undefined'.

2 var __importDefault = (this && this.__importDefault) || function (mod) {
~~~~

at createTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1433:41)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1617:30)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
at require.extensions.<computed> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at Object.require.extensions.<computed> [as .ts] (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at /Users/marlon/Javascript/ce-discord-bot/node_modules/esm/esm.js:1:251778

at esmImport (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:48:11)
at importSync (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:70:26)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:38:46)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:34:17)
at scanCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:55:5)
at getCommandObjects (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:61:26)
at deployCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:87:22)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/index.ts:36:5)
Error:
Failed to import from:
/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/commands/alerts/alerts.ts.
Options:
{}
Require error message:
TSError: ⨯ Unable to compile TypeScript:
src/commands/alerts/functions.ts:2:32 - error TS2532: Object is possibly 'undefined'.

2 var __importDefault = (this && this.__importDefault) || function (mod) {
~~~~

at createTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1433:41)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1617:30)
at Object.m._compile (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
at require.extensions.<computed> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at Object.require.extensions.<computed> [as .ts] (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/ts-node/src/index.ts:1621:12)
at /Users/marlon/Javascript/ce-discord-bot/node_modules/esm/esm.js:1:251778

at esmImport (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:48:11)
at importSync (/Users/marlon/Javascript/communaute-events/ce-discord-bot/node_modules/import-sync/src/import.ts:70:26)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:38:46)
at scanDirectory (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:34:17)
at scanCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:55:5)
at getCommandObjects (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:61:26)
at deployCommands (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/core/deploy-commands.ts:87:22)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (/Users/marlon/Javascript/communaute-events/ce-discord-bot/src/index.ts:36:5)
The code in question: https://srcb.in/HRuwOaDSwE To load this file, i'm using the "import-sync" module.
const module = importSync(filePath)
const module = importSync(filePath)
22 replies
DIAdiscord.js - Imagine an app
Created by Ori on 10/12/2023 in #djs-questions
Weird slash command registering problem
Hello, i'm having a weird issue where not logging (console.log) the result of rest.put does not register the slash command Not working:
for (const [guild, commands] of Object.entries(guildCommands)) {
console.log(chalk.cyan(`Started reloading "${guild}" (/)`));
const data = await rest.put(
Routes.applicationGuildCommands(config.clientId, guild),
{ body: commands },
);
console.log(chalk.green(`Reloaded ${commands.length} commands for "${guild}"`))
}
for (const [guild, commands] of Object.entries(guildCommands)) {
console.log(chalk.cyan(`Started reloading "${guild}" (/)`));
const data = await rest.put(
Routes.applicationGuildCommands(config.clientId, guild),
{ body: commands },
);
console.log(chalk.green(`Reloaded ${commands.length} commands for "${guild}"`))
}
Working:
for (const [guild, commands] of Object.entries(guildCommands)) {
console.log(chalk.cyan(`Started reloading "${guild}" (/)`));
const data = await rest.put(
Routes.applicationGuildCommands(config.clientId, guild),
{ body: commands },
);
console.log(data) // here
console.log(chalk.green(`Reloaded ${commands.length} commands for "${guild}"`))
for (const [guild, commands] of Object.entries(guildCommands)) {
console.log(chalk.cyan(`Started reloading "${guild}" (/)`));
const data = await rest.put(
Routes.applicationGuildCommands(config.clientId, guild),
{ body: commands },
);
console.log(data) // here
console.log(chalk.green(`Reloaded ${commands.length} commands for "${guild}"`))
}
5 replies
DIAdiscord.js - Imagine an app
Created by Ori on 10/9/2023 in #djs-questions
Commands not registering to guild
I'm coding a bot template, and I want to make a folder-based command registration system (see the images below) However, i'm having trouble with registering the commands. My global commands don't register at all The guild specific commands are global
9 replies