SowerofSystems
SowerofSystems
DIAdiscord.js - Imagine an app
Created by SowerofSystems on 8/10/2024 in #djs-questions
Reaction Collector not collecting reactions in DMs
discordjs 14.12.1
// Create a reaction collector
const filter = (reaction, user) => {
console.log(`Reaction: ${reaction.emoji.name}, User: ${user.tag}`);
return ['👍', '👎'].includes(reaction.emoji.name) && !user.bot;
};

const collector = message.createReactionCollector({ filter, time: 60000 });

console.log('Collector created:', collector);

collector.on('collect', async (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);

try {
// Check if the reaction is on an invitation message
const memberRecord = await Database.CoffeeChat.findOne({ where: { MemberId: user.id, InvitationMessageId: reaction.message.id } });
if (memberRecord && memberRecord.OptedIn) {
let response;
if (reaction.emoji.name === '👍') {
response = true;
} else if (reaction.emoji.name === '👎') {
response = false;
}

// Update the database with the user's response
await Database.CoffeeChat.update(
{ OptedIn: response },
{ where: { InvitationMessageId: reaction.message.id } }
);
// Create a reaction collector
const filter = (reaction, user) => {
console.log(`Reaction: ${reaction.emoji.name}, User: ${user.tag}`);
return ['👍', '👎'].includes(reaction.emoji.name) && !user.bot;
};

const collector = message.createReactionCollector({ filter, time: 60000 });

console.log('Collector created:', collector);

collector.on('collect', async (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);

try {
// Check if the reaction is on an invitation message
const memberRecord = await Database.CoffeeChat.findOne({ where: { MemberId: user.id, InvitationMessageId: reaction.message.id } });
if (memberRecord && memberRecord.OptedIn) {
let response;
if (reaction.emoji.name === '👍') {
response = true;
} else if (reaction.emoji.name === '👎') {
response = false;
}

// Update the database with the user's response
await Database.CoffeeChat.update(
{ OptedIn: response },
{ where: { InvitationMessageId: reaction.message.id } }
);
35 replies
DIAdiscord.js - Imagine an app
Created by SowerofSystems on 5/26/2024 in #djs-questions
Censor failing to detect words containing regex symbols
I have a censor event that pulls the list of banned words, which may be preceded and/or followed by an * to mimic the Discord censor behavior. However, while I am escaping regex symbols before testing the word, my censor is failing to pick up words that contain regex symbols, and I can't for the life of me figure out why.
// Fetch all banned words from the database for the current server
const bannedWords = await Database.BannedWord.findAll({
include: [{
model: Database.Server,
where: { ServerId: message.guild.id }
}]
});

// Check if the message includes any banned word
for (const bannedWord of bannedWords) {
let word = bannedWord.Word;
let regex;
// Fetch all banned words from the database for the current server
const bannedWords = await Database.BannedWord.findAll({
include: [{
model: Database.Server,
where: { ServerId: message.guild.id }
}]
});

// Check if the message includes any banned word
for (const bannedWord of bannedWords) {
let word = bannedWord.Word;
let regex;
12 replies
DIAdiscord.js - Imagine an app
Created by SowerofSystems on 5/25/2024 in #djs-questions
Error when trying to upload global slash commands
I have no idea why I am getting this error. When I register slash commands locally everything works fine, but when I set runBot(global = true) I get the following error:
node .
v22.2.0
Configuration file not found. Using a basic database...
Found 20 command files.
Finished loading commands.
Found 8 event files.
Finished loading events.
Failed to log in: TypeError: global.FinalizationRegistry is not a constructor
at new WeakSessionCache (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\core\connect.js:23:31)
at buildConnector (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\core\connect.js:82:24)
at new Pool (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\pool.js:55:17)
at Agent.defaultFactory (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\agent.js:22:7)
at [dispatch] (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\agent.js:93:34)
at Intercept (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\interceptor\redirect-interceptor.js:11:16)
at [Intercepted Dispatch] (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\dispatcher-base.js:158:12)
at Agent.dispatch (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\dispatcher-base.js:179:40)
at Agent.request (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\api\api-request.js:171:10)
at C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\api\api-request.js:164:15
Database synced successfully.
Database initialized successfully.
node .
v22.2.0
Configuration file not found. Using a basic database...
Found 20 command files.
Finished loading commands.
Found 8 event files.
Finished loading events.
Failed to log in: TypeError: global.FinalizationRegistry is not a constructor
at new WeakSessionCache (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\core\connect.js:23:31)
at buildConnector (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\core\connect.js:82:24)
at new Pool (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\pool.js:55:17)
at Agent.defaultFactory (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\agent.js:22:7)
at [dispatch] (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\agent.js:93:34)
at Intercept (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\interceptor\redirect-interceptor.js:11:16)
at [Intercepted Dispatch] (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\dispatcher-base.js:158:12)
at Agent.dispatch (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\dispatcher\dispatcher-base.js:179:40)
at Agent.request (C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\api\api-request.js:171:10)
at C:\Users\tomja\AppData\Roaming\nvm\v22.2.0\node_modules\djsbotbuilder\node_modules\undici\lib\api\api-request.js:164:15
Database synced successfully.
Database initialized successfully.
5 replies
DIAdiscord.js - Imagine an app
Created by SowerofSystems on 5/10/2024 in #djs-questions
Failing to trigger collector
Console Log:
Message component collector created
Collect event handler added
Message component collector created
Collect event handler added
When I click a button discord responds with 'This interaction failed' after 3 seconds. Based on the console logs it seems like the collector is not being triggered. At the very least the filter is never called.
6 replies
DIAdiscord.js - Imagine an app
Created by SowerofSystems on 12/30/2023 in #djs-questions
Bot crashes during second /command use
My clear-table command works perfectly the first time you use /clear-table, but the second time, it crashes when you click the Clear Table button. I am new to discordjs and this is my first time using components and collectors. https://gist.github.com/SowerofSystems/3f482470630ae1f90bcb526fecd6f3ff
8 replies