DanielBA
DanielBA
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 11/15/2023 in #djs-questions
Can large files cause abortion errors?
My bot sends a .png file across many servers. Most of the come out with abortion errors, meaning the API request timed out. The .png file weighs 370KB and when I switch it to a smaller one that only weighs 50KB the code works perfectly
6 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 8/7/2023 in #djs-questions
Recoursive Error
7 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 7/20/2023 in #djs-questions
New slash commands not registering
Two of my slash commands (new ones, created after the last deployment) are not being registered. I checked that the array I use for the deployment does include them, yet they are still not being registered. Example code of one of the slash command files
const config = require('../config.json');
const mongoose = require('mongoose');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setName("unmute")
.setDescription("הסרת מיוט")
.addUserOption(option =>
option
.setName("user")
.setDescription("המשתמש")
.setRequired(true)
)
,
async execute(interaction, client) {
const member = interaction.options.getMemberOption("user");

const role = interaction.guild.roles.cache.get(config.muteRole);

if (!member)
return interaction.reply("משתמש זה אינו נמצא בשרת");

if (!member.roles.cache.some(r => r.id === role.id)) return interaction.reply({ephemeral: true, content: "למשתמש זה אין מיוט פעיל"});
member.roles.remove(role);

const Embed = new EmbedBuilder()
.setTitle("נתינת מיוט על ידי חבר צוות")
.setColor(0x32FF32)
.setTimestamp()
.addFields(
{name: "מסיר:", value: `${interaction.user}`},
{name: "מקבל:", value: `${member}`}
)

interaction.reply("המיוט ניתן בהצלחה");
interaction.guild.channels.cache.get(config.mutesRoom).send({embeds: [Embed]})
},
};
const config = require('../config.json');
const mongoose = require('mongoose');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setName("unmute")
.setDescription("הסרת מיוט")
.addUserOption(option =>
option
.setName("user")
.setDescription("המשתמש")
.setRequired(true)
)
,
async execute(interaction, client) {
const member = interaction.options.getMemberOption("user");

const role = interaction.guild.roles.cache.get(config.muteRole);

if (!member)
return interaction.reply("משתמש זה אינו נמצא בשרת");

if (!member.roles.cache.some(r => r.id === role.id)) return interaction.reply({ephemeral: true, content: "למשתמש זה אין מיוט פעיל"});
member.roles.remove(role);

const Embed = new EmbedBuilder()
.setTitle("נתינת מיוט על ידי חבר צוות")
.setColor(0x32FF32)
.setTimestamp()
.addFields(
{name: "מסיר:", value: `${interaction.user}`},
{name: "מקבל:", value: `${member}`}
)

interaction.reply("המיוט ניתן בהצלחה");
interaction.guild.channels.cache.get(config.mutesRoom).send({embeds: [Embed]})
},
};
Code for the deployment:
let slashCommands = [];
client.slashCommands = new Discord.Collection();
const slashCommandFiles = fs.readdirSync('./slashCommands');
for (const file of slashCommandFiles) {
if (!file.endsWith(".js")) continue;
const command = require(`../slashCommands/${file}`);
client.slashCommands.set(command.data.name, command);
slashCommands.push(command.data);
}
try {
console.log(slashCommands);
await rest.put(Routes.applicationGuildCommands(config.botID, config.guildID), { body: slashCommands});
console.log("application commands refreshed")
} catch(error) {console.log(error)}
let slashCommands = [];
client.slashCommands = new Discord.Collection();
const slashCommandFiles = fs.readdirSync('./slashCommands');
for (const file of slashCommandFiles) {
if (!file.endsWith(".js")) continue;
const command = require(`../slashCommands/${file}`);
client.slashCommands.set(command.data.name, command);
slashCommands.push(command.data);
}
try {
console.log(slashCommands);
await rest.put(Routes.applicationGuildCommands(config.botID, config.guildID), { body: slashCommands});
console.log("application commands refreshed")
} catch(error) {console.log(error)}
9 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 4/26/2023 in #djs-questions
Handling StringSelectMenuInteraction
const value = menu.values[0];
const value = menu.values[0];
This is how I read the current selected value from a <StringSelectMenuCopmonent>. I receive an error stating menu.values is undefined. Why is that?
8 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 3/15/2023 in #djs-questions
Message fetching
I have this function which edits a message anytime it is called, or re-sends it if it was deleted. I have noticed that when I restart the bot, it won't recognize the message and resend it, then start editing the new message. What is the cause of this and how can I fix it?
const settings = mongoose.model('Settings');

const ids = await settings.findOne({name: "updatedReport"});
const channelID = ids ? ids.value.split("-")[0] : config.updateReportRoom;
const channel = client.guilds.cache.get(config.guildID).channels.cache.get(channelID);
if (!channel) return;

const embeds = await msg(client);
let message;

if (ids) {
const messageID = ids.value.split("-")[1];
message = await channel.messages.cache.get(messageID);
if (!message) {
message = await channel.send("Working...");
ids.value = channelID + "-" + message.id;
await ids.save();
}
}
else {
message = await channel.send("Working...");
const doc = new settings();
doc.name = "updatedReport";
doc.value = channelID + "-" + message.id;
await doc.save();
}

message.edit({content: "", embeds: embeds});
const settings = mongoose.model('Settings');

const ids = await settings.findOne({name: "updatedReport"});
const channelID = ids ? ids.value.split("-")[0] : config.updateReportRoom;
const channel = client.guilds.cache.get(config.guildID).channels.cache.get(channelID);
if (!channel) return;

const embeds = await msg(client);
let message;

if (ids) {
const messageID = ids.value.split("-")[1];
message = await channel.messages.cache.get(messageID);
if (!message) {
message = await channel.send("Working...");
ids.value = channelID + "-" + message.id;
await ids.save();
}
}
else {
message = await channel.send("Working...");
const doc = new settings();
doc.name = "updatedReport";
doc.value = channelID + "-" + message.id;
await doc.save();
}

message.edit({content: "", embeds: embeds});
3 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 12/24/2022 in #djs-questions
function will sometimes not be called
3 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 11/2/2022 in #djs-questions
voicestate is undefined
client.on('voiceStateUpdate', (oldState, newState) => {
voiceClient.startListener(oldState, newState);
console.log(voiceClient.getUserData(client.guilds.cache.get(guildID).members.cache.get(newState.id)))
})
client.on('voiceStateUpdate', (oldState, newState) => {
voiceClient.startListener(oldState, newState);
console.log(voiceClient.getUserData(client.guilds.cache.get(guildID).members.cache.get(newState.id)))
})
Inside of the console.log() I am trying to log the user data of the state's user, but as I try and do that, I get an error saying Can't read properties of undefined reading 'id', yet, When I try and log the voiceState it logs fine. Am I doing something wrong here?
6 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 11/2/2022 in #djs-voice
voiceState is undefined
client.on('voiceStateUpdate', (oldState, newState) => {
voiceClient.startListener(oldState, newState);
console.log(voiceClient.getUserData(client.guilds.cache.get(guildID).members.cache.get(newState.id)))
})
client.on('voiceStateUpdate', (oldState, newState) => {
voiceClient.startListener(oldState, newState);
console.log(voiceClient.getUserData(client.guilds.cache.get(guildID).members.cache.get(newState.id)))
})
Inside of the console.log() I am trying to log the user data of the state's user, but as I try and do that, I get an error saying Can't read properties of undefined reading 'id', yet, When I try and log the voiceState it logs fine. Am I doing something wrong here?
9 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 10/20/2022 in #djs-questions
How to edit a value inside of a collection
What I am looking for is just as the title says
8 replies
DIAdiscord.js - Imagine a boo! 👻
Created by DanielBA on 10/19/2022 in #djs-questions
Collections problem
javascript
const debounce = new Discord.Collection();
if (debounce.findKey(id => id === interaction.message.id)) {
console.log(1)
if (debounce[interaction.message.id].length === interaction.message.embeds[0].data.fields[1].value) {console.log(11); return; }
debounce[interaction.message.id].push(interaction.user)
} else {
console.log(2)
debounce[interaction.message.id] = [interaction.user];
}
javascript
const debounce = new Discord.Collection();
if (debounce.findKey(id => id === interaction.message.id)) {
console.log(1)
if (debounce[interaction.message.id].length === interaction.message.embeds[0].data.fields[1].value) {console.log(11); return; }
debounce[interaction.message.id].push(interaction.user)
} else {
console.log(2)
debounce[interaction.message.id] = [interaction.user];
}
does someone know why it logs 2 and only then 1? Also, why does debounce.findKey always returns undefined?
10 replies