Schlaumeyer
Schlaumeyer
DIAdiscord.js - Imagine an app
Created by Schlaumeyer on 12/3/2023 in #djs-questions
Sometimes Unknown Interaction
Hey, I made a discordjs Bot that relies heavily on slash commands, sadly sometimes it gives out just unknown interaction and crashes the bot. In this example, as soon as the command is fired, it crashed. But there are multile files/commands like this. The interaction.deffer() is just experimental
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { client } from '../other/client.js';
import { dbQuery } from '../other/database.js';
import { isInEventTime } from '../other/functions.js';
const embed_color = ['#4285F4', '#34A853', '#FBBC05', '#EA4335', '#0F9D58', '#551A8B', '#008080', '#800000', '#86feff', '#8de2ff', '#c3f9ff', '#00d9e6', '#00e4ff'];
const embed_footer = 'by @schlaumeyer';

const notifyCommand = new SlashCommandBuilder()
.setName('notify')
.setDescription('Pingt dich, wenn du wieder /collect ausführen kannst')
.addBooleanOption((option) =>
option
.setName('set')
.setDescription('Pingt dich, wenn du wieder /collect ausführen kannst')
.setRequired(true)
)

client.on('interactionCreate', async (interaction) => {
interaction.deferReply();

const { commandName } = interaction;

try {
if (commandName === 'notify') {
// if (await isInEventTime(interaction)) { return };

let notification = interaction.options.getBoolean('set');
let result = await dbQuery('SELECT * FROM leaderboard');
let resIndex = result.findIndex((obj => obj.userID == interaction.user.id));
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { client } from '../other/client.js';
import { dbQuery } from '../other/database.js';
import { isInEventTime } from '../other/functions.js';
const embed_color = ['#4285F4', '#34A853', '#FBBC05', '#EA4335', '#0F9D58', '#551A8B', '#008080', '#800000', '#86feff', '#8de2ff', '#c3f9ff', '#00d9e6', '#00e4ff'];
const embed_footer = 'by @schlaumeyer';

const notifyCommand = new SlashCommandBuilder()
.setName('notify')
.setDescription('Pingt dich, wenn du wieder /collect ausführen kannst')
.addBooleanOption((option) =>
option
.setName('set')
.setDescription('Pingt dich, wenn du wieder /collect ausführen kannst')
.setRequired(true)
)

client.on('interactionCreate', async (interaction) => {
interaction.deferReply();

const { commandName } = interaction;

try {
if (commandName === 'notify') {
// if (await isInEventTime(interaction)) { return };

let notification = interaction.options.getBoolean('set');
let result = await dbQuery('SELECT * FROM leaderboard');
let resIndex = result.findIndex((obj => obj.userID == interaction.user.id));
13 replies
DIAdiscord.js - Imagine an app
Created by Schlaumeyer on 7/29/2023 in #djs-questions
Error when creating embed
I'm getting the following error when trying to create an embed. My main goal is to let the user enter the name, select an image and unix time to create an embed.
[29.07.2023 16:56.55.954] [ERROR] Error creating embed: Received one or more errors
[29.07.2023 16:56.55.955] [ERROR] Error details: CombinedError (3)
Received one or more errors

1 ExpectedValidationError > s.literal(V)
| Expected values to be equals
|
| Expected:
| | null
|
| Received:
| | '#e76604'

2 ValidationError > s.number
| Expected a number primitive
|
| Received:
| | '#e76604'

3 ValidationError > s.tuple(T)
| Expected an array
|
| Received:
| | '#e76604'

at UnionValidator.handle (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/node_modules/@sapphire/shapeshift/dist/index.mjs:1096:23)
at UnionValidator.parse (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/node_modules/@sapphire/shapeshift/dist/index.mjs:204:88)
at EmbedBuilder.setColor (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/node_modules/@discordjs/builders/dist/index.mjs:225:20)
at createFiresaleEmbed (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/src/commands/firesale.js:20:14)
at Client.<anonymous> (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/src/commands/firesale.js:96:27)
at Client.emit (node:events:526:35)
at InteractionCreateAction.handle (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\websocket\WebSocketManager.js:354:31)
at WebSocketManager.<anonymous> (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\websocket\WebSocketManager.js:238:12)
[29.07.2023 16:56.55.954] [ERROR] Error creating embed: Received one or more errors
[29.07.2023 16:56.55.955] [ERROR] Error details: CombinedError (3)
Received one or more errors

1 ExpectedValidationError > s.literal(V)
| Expected values to be equals
|
| Expected:
| | null
|
| Received:
| | '#e76604'

2 ValidationError > s.number
| Expected a number primitive
|
| Received:
| | '#e76604'

3 ValidationError > s.tuple(T)
| Expected an array
|
| Received:
| | '#e76604'

at UnionValidator.handle (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/node_modules/@sapphire/shapeshift/dist/index.mjs:1096:23)
at UnionValidator.parse (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/node_modules/@sapphire/shapeshift/dist/index.mjs:204:88)
at EmbedBuilder.setColor (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/node_modules/@discordjs/builders/dist/index.mjs:225:20)
at createFiresaleEmbed (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/src/commands/firesale.js:20:14)
at Client.<anonymous> (file:///C:/Users/Leon/OneDrive/Desktop/DKK%20v14/src/commands/firesale.js:96:27)
at Client.emit (node:events:526:35)
at InteractionCreateAction.handle (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\websocket\WebSocketManager.js:354:31)
at WebSocketManager.<anonymous> (C:\Users\Leon\OneDrive\Desktop\DKK v14\node_modules\discord.js\src\client\websocket\WebSocketManager.js:238:12)
My code looks as follows:
let name = options.getString('name')
let image1 = options.getAttachment('bild1')
let image2 = options.getAttachment('bild2')
let image3 = options.getAttachment('bild3')
let unix = options.getInteger('unix')

const embed = createFiresaleEmbed(event.title, name, unix, image1.url, event.color);

interaction.reply({
content: 'Test',
embeds: [embed],
ephemeral: true
});
let name = options.getString('name')
let image1 = options.getAttachment('bild1')
let image2 = options.getAttachment('bild2')
let image3 = options.getAttachment('bild3')
let unix = options.getInteger('unix')

const embed = createFiresaleEmbed(event.title, name, unix, image1.url, event.color);

interaction.reply({
content: 'Test',
embeds: [embed],
ephemeral: true
});
function createFiresaleEmbed(title, name, unix, image, color) {
try {
return new EmbedBuilder()
.setTitle(title)
.setColor(color)
.setDescription(Dieses Mal einen **${name}**!\n\nDer Fire Sale startet <t:${unix}:R>\n\n) //Took out Gravis to not f up discord formatting
.setImage(image)
.setFooter({ text: config.global.footer });
} catch (error) {
console.error(Error creating embed: ${error.message}); //Took out Gravis to not f up discord formatting
console.error("Error details:", error);
return null;
}
}
function createFiresaleEmbed(title, name, unix, image, color) {
try {
return new EmbedBuilder()
.setTitle(title)
.setColor(color)
.setDescription(Dieses Mal einen **${name}**!\n\nDer Fire Sale startet <t:${unix}:R>\n\n) //Took out Gravis to not f up discord formatting
.setImage(image)
.setFooter({ text: config.global.footer });
} catch (error) {
console.error(Error creating embed: ${error.message}); //Took out Gravis to not f up discord formatting
console.error("Error details:", error);
return null;
}
}
I logged all the variables title, name, unix, image and color: the values seem to be ok
console.log(title);
console.log(name);
console.log(unix);
console.log(image);
console.log(color);
console.log(title);
console.log(name);
console.log(unix);
console.log(image);
console.log(color);
[29.07.2023 16:59.54.946] [LOG] 🔥 Neuer Fire Sale! [29.07.2023 16:59.54.947] [LOG] testa [29.07.2023 16:59.54.947] [LOG] 1690649796 [29.07.2023 16:59.54.948] [LOG] https://cdn.discordapp.com/ephemeral-attachments/1066036486497112075/1134862857813622804/7ify6m.jpg [29.07.2023 16:59.54.948] [LOG] #e76604
6 replies
DIAdiscord.js - Imagine an app
Created by Schlaumeyer on 1/22/2023 in #djs-questions
TypeError: Cannot read properties of undefined (reading 'send')
That's my code in the index.js file: https://hst.sh/xabavudika.js I get the error in the title. I make this promise to wait for it in another file but I just tested it in the index.js What can be the issue? The channel ID is correct.
13 replies
DIAdiscord.js - Imagine an app
Created by Schlaumeyer on 1/21/2023 in #djs-questions
Cannot read properties of undefined (reading 'send')
I'm awaiting the ready event from my bot to send a message. Sadly that doesn't work. Any ideas?
(async () => {
try {
await ready;
client.channels.cache.get(channelID).send({ content: " ", embeds: [embed_events] }).then(sent => {
databases.overview.message_id = sent.id;
});
} catch (err) {
console.error(err);
}
})();
(async () => {
try {
await ready;
client.channels.cache.get(channelID).send({ content: " ", embeds: [embed_events] }).then(sent => {
databases.overview.message_id = sent.id;
});
} catch (err) {
console.error(err);
}
})();
Error:
TypeError: Cannot read properties of undefined (reading 'send')
TypeError: Cannot read properties of undefined (reading 'send')
12 replies
DIAdiscord.js - Imagine an app
Created by Schlaumeyer on 1/15/2023 in #djs-questions
Get variable to other file
Hey, my code is the following: index.js
import { } from './events/myfile.js'

let result = await fetch('API');
let events = await result.json()

export { events };
import { } from './events/myfile.js'

let result = await fetch('API');
let events = await result.json()

export { events };
myfile.js
import { events } from "./../index.js";

console.log(events);
import { events } from "./../index.js";

console.log(events);
The error I get
ReferenceError: Cannot access 'events' before initialization
ReferenceError: Cannot access 'events' before initialization
What am I doing wrong?
3 replies
DIAdiscord.js - Imagine an app
Created by Schlaumeyer on 11/16/2022 in #djs-questions
Check if optional argument in commnd was provided
Hey, I have a command called /stats It will provide the stats for the user who entered the command, the command also has a optional argument (user mention) with which the user can get the stats of another user. How can I check if the argument is provided because now I just get an error when only the /stats command is entered
8 replies