luzede
luzede
DIAdiscord.js - Imagine an app
Created by luzede on 6/17/2024 in #djs-questions
client.on() not handling/accepting requests when awaiting response from SQLite when it is busy
This is how I register events in index.ts
for (const event of events) {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, commands, db));
} else {
client.on(event.name, (...args) => {
event.execute(...args, commands, db);
});
}
}
for (const event of events) {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, commands, db));
} else {
client.on(event.name, (...args) => {
event.execute(...args, commands, db);
});
}
}
This code is run on "InteractionCreate" event
await interaction.deferReply({ ephemeral: false });
await command.execute(interaction, db);
await interaction.deferReply({ ephemeral: false });
await command.execute(interaction, db);
The first interaction gets received and runs deferReply and then execute(interaction, db) But while the call to the database
await insertNewBanRecord(db, {
user_id: target_member.id,
guild_id: interaction.guild.id,
banner_id: banner_member.id,
ban_duration_minutes: duration,
reason: reason,
});
await insertNewBanRecord(db, {
user_id: target_member.id,
guild_id: interaction.guild.id,
banner_id: banner_member.id,
ban_duration_minutes: duration,
reason: reason,
});
is running inside the execute(interaction, db) Any more slash command requests are not going through the client.on(Events.InteractionCreate, ...) event handler. Only when the call to the database is finished it receives responses. I tried using sleep command to see if by stopping the interaction from executing, subsequent calls would be ignored or not, but they were not, all the InteractionCreate events were going through and deferred even though the previous one had not finished fully responding. I use better-sqlite3 and kysely query builder and orm. database.ts
const dialect = new SqliteDialect({
database: new SQLite("src/database/main.db"),
});

const db = new Kysely<Database>({
dialect,
});

export default db;
const dialect = new SqliteDialect({
database: new SQLite("src/database/main.db"),
});

const db = new Kysely<Database>({
dialect,
});

export default db;
index.ts
const client = new Client({
intents: [...],
});

for (const event of events) {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, commands, db));
} else {
client.on(event.name, (...args) => {
event.execute(...args, commands, db);
});
}
}
client.login(config.TOKEN);
const client = new Client({
intents: [...],
});

for (const event of events) {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, commands, db));
} else {
client.on(event.name, (...args) => {
event.execute(...args, commands, db);
});
}
}
client.login(config.TOKEN);
7 replies
DIAdiscord.js - Imagine an app
Created by luzede on 6/16/2024 in #djs-questions
Any performance issues if non-async function runs an async, compared to running async alone
On discordjs.guide, this is suggested
for (const event of events) {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => {
event.execute(...args);
});
}
}
for (const event of events) {
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => {
event.execute(...args);
});
}
}
But if I were to write manually
client.on(Events.InteractionCreate, async (interaction) -> {...}
client.on(Events.InteractionCreate, async (interaction) -> {...}
It would be like this, where the function in the client.on parameter would be async. In the first one though, it is non-async function running an async function, will it have any performance issues?
3 replies
DIAdiscord.js - Imagine an app
Created by luzede on 7/11/2022 in #djs-questions
message.delete is not a function (while deleting a reply to a command in DM)
await interaction.editReply(`Done! I counted to ${number}`)
.then(message => setTimeout(() => message.delete(), 3000))
await interaction.editReply(`Done! I counted to ${number}`)
.then(message => setTimeout(() => message.delete(), 3000))
On server the reply message is getting deleted normally but when I do it to replies in DM it fails and the program stops. Gives the following error: TypeError: message.delete is not a function I would use deleteReply() but that does not work when I have edited the message with editReply(). deleteReply() works in DMs but only if I didn't edit the message.
1 replies