ncls.
ncls.
DIAdiscord.js - Imagine an app
Created by ncls. on 6/2/2023 in #djs-questions
deferReply not working on specific server
Hello. We are running a small hosting service for Discord bots but one of our servers can't execute editReply from DIscord.js. Discord.py works just fine. The bots just stay on "is thinking..." until that eventually times out. After around 35 minutes the console shows an API error "Invalid Webhook Token". The weird thing is that everything else works fine and as I said, with Python bots it works as well. It's just the editReply function on this one particular server. Does anyone have an idea what the issue might be or how to solve this?
26 replies
DIAdiscord.js - Imagine an app
Created by ncls. on 11/3/2022 in #djs-questions
How to remove this listener in another file?
Hello, So I have set up a listener like this:
const notify = require(`${process.cwd()}/utils/notify`);

user.client.addListener("voiceStateUpdate", (oldState, newState) => notify(oldState, newState));
const notify = require(`${process.cwd()}/utils/notify`);

user.client.addListener("voiceStateUpdate", (oldState, newState) => notify(oldState, newState));
notify.js obviously includes the function that should get triggered once the voice state of the specific user updates. Now I want to remove that listener again in another file later on. Issue is that I have no idea how to do that. Can someone help?
36 replies
DIAdiscord.js - Imagine an app
Created by ncls. on 11/3/2022 in #djs-questions
removeListener of anonymous or imported function
Hello, I am currently building a bot that notifies people when someone goes live in a voice chat. The issue is, that when I want to remove the listener, I can't because it's an anonymous function. When I try to introduce an imported/required function, it crashes because oldState and newState are not defined. How can I remove the listener?
const notify = require(`${process.cwd()}/utils/notify`);

user.client.removeListener("voiceStateUpdate", notify(oldState, newState);
const notify = require(`${process.cwd()}/utils/notify`);

user.client.removeListener("voiceStateUpdate", notify(oldState, newState);
6 replies
DIAdiscord.js - Imagine an app
Created by ncls. on 11/3/2022 in #djs-questions
How to check if a specific user is streaming (screen share or camera) in any voice channel?
Hello, I'm currently trying to figure out how to check whether a specific user is streaming in any voice channel on the server. Streaming means either screen share or camera (If camera isn't possible, let me know) What's the best way to do this? Currently I'm just listening to the user's presenceUpdate event.
6 replies
DIAdiscord.js - Imagine an app
Created by ncls. on 11/1/2022 in #djs-questions
Check if a custom emoji is a valid emoji my bot can use
Hello, I'm trying to get my bot to check it the emoji code a user enters is a valid emoji that the bot can use in a button or not but I have no idea how to do that. Does someone have a solution?
15 replies
DIAdiscord.js - Imagine an app
Created by ncls. on 10/31/2022 in #djs-questions
switch statement not triggering in catch function
Hi, I'm trying to handle errors when trying to fetch a message but it just doesn't run the switch statement. Does someone have an idea why?
const msg = await channel.messages.fetch(serverConfig.ticketMessage.id).catch(e => {
console.log("Error", e.status); // gets logged
switch (e.status) {
case 404:
interaction.reply({ content: `The message could not be edited. It may have been deleted.` }); // does not get logged
return;
case 403:
interaction.reply({ content: `The message could not be edited. I don't have access to the channel.` }); // does not get logged
return;
default:
console.log("Test"); // does not get logged
break;
}
console.log("Test 2"); // does not get logged
});
const msg = await channel.messages.fetch(serverConfig.ticketMessage.id).catch(e => {
console.log("Error", e.status); // gets logged
switch (e.status) {
case 404:
interaction.reply({ content: `The message could not be edited. It may have been deleted.` }); // does not get logged
return;
case 403:
interaction.reply({ content: `The message could not be edited. I don't have access to the channel.` }); // does not get logged
return;
default:
console.log("Test"); // does not get logged
break;
}
console.log("Test 2"); // does not get logged
});
9 replies
DIAdiscord.js - Imagine an app
Created by ncls. on 10/31/2022 in #djs-questions
Handle Subcommands in SubcommandGroups
Hello, I'm working with SubcommandGroups atm and I'm trying to figure out how I can handle SubcommandGoups aswell. The issue is that I'm loading my commands and Subcommands into collections as every bot tutorial tells you to. Now I have client.slashCommands and client.subcommands as collections for my commands. Now, how do I properly manage subcommandgroups in there as well so that it's still clear to what subcommand they belong? Does it make sense to store them as an object? Like
client.commands = {}
// Loading slash commands
fs.readdirSync("./slashCommands")
.filter(file => file.endsWith(".js"))
.forEach(file => {
console.log(`Loading slash command ${file}...`);
let pull = require(`./slashCommands/${file}`);
client.commands[pull.name] = pull;
console.log("Loaded!");
});



// Loading subcommands
fs.readdirSync("./slashCommands/subCommands")
.forEach(dir => {
fs.readdirSync(`./slashCommands/subCommands/${dir}/`)
.filter(file => file.endsWith(".js"))
.forEach(file => {
console.log(`Loading ${dir} subcommand ${file}...`);
let pull = require(`./slashCommands/subCommands/${dir}/${file}`);
client.commands[dir][pull.name] = pull;
console.log("Loaded!");
});
});
client.commands = {}
// Loading slash commands
fs.readdirSync("./slashCommands")
.filter(file => file.endsWith(".js"))
.forEach(file => {
console.log(`Loading slash command ${file}...`);
let pull = require(`./slashCommands/${file}`);
client.commands[pull.name] = pull;
console.log("Loaded!");
});



// Loading subcommands
fs.readdirSync("./slashCommands/subCommands")
.forEach(dir => {
fs.readdirSync(`./slashCommands/subCommands/${dir}/`)
.filter(file => file.endsWith(".js"))
.forEach(file => {
console.log(`Loading ${dir} subcommand ${file}...`);
let pull = require(`./slashCommands/subCommands/${dir}/${file}`);
client.commands[dir][pull.name] = pull;
console.log("Loaded!");
});
});
10 replies
DIAdiscord.js - Imagine an app
Created by ncls. on 7/27/2022 in #djs-voice
Somehow getVoiceConnection(guildId) returns undefined
Well, as the title already says, Somehow getVoiceConnection(guildId) returns undefined. I'm following this tutorial: https://youtu.be/oRWAuXqCuYA?t=841 (Timestamp is where the function is used). Node v16.14.2 discord.js v14.0.3 discordjs/voice v0.11.0
6 replies