id command to fetch the id for a modmail target

This commit is contained in:
Erik 2021-09-03 10:34:16 +03:00
parent 75c5a9cc71
commit db0cf09e55
No known key found for this signature in database
GPG Key ID: 7E862371D3409F16

39
structure/commands/Id.js Normal file
View File

@ -0,0 +1,39 @@
const Command = require('../Command');
class ModmailID extends Command {
constructor(client) {
super(client, {
name: 'id',
aliases: ['mmid']
});
}
async execute(message, { args }) {
let channel = null;
if (args?.length) {
const [ch] = args;
channel = await this.client.resolveChannel(ch);
} else {
({ channel } = message);
}
const chCache = this.client.cache.channels;
const result = Object.entries(chCache).find(([, val]) => {
return val === channel.id;
});
if (!result) return {
error: true,
msg: `This doesn't seem to be a valid modmail channel. Cache might be out of sync. **[MISSING TARGET]**`
};
const [userId] = result;
return userId;
}
}
module.exports = ModmailID;