discord-freepbx-manager/interactionHandlers/commands/list.js

36 lines
847 B
JavaScript

const Discord = require('discord.js');
const pool = global.pool
const fpbx = global.fpbx
const client = global.client
const log = global.log
module.exports = {};
module.exports.execute = async (interaction) => {
const lookup = await pool.query('SELECT * FROM discord_users');
// lookup: [ { extension: '1001', discord_id: '1234567890' } ]
const embeds = [];
let description = '';
lookup.forEach((row, index) => {
const line = `${row.extension}: <@${row.discordId}>\n`;
if (description.length > 2048) {
embeds.push({
description
});
description = '';
}
description += line;
});
if (description.length > 0) {
embeds.push({
description
});
}
embeds.forEach(async (embed) => {
await interaction.user.send({ embeds: [embed] });
})
await interaction.reply({ ephemeral: true, content: "Check your DMs!" });
}