Skip to content

Instantly share code, notes, and snippets.

@vintprox
Created August 30, 2019 19:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vintprox/4ebb5db85a36668833a0c4f09dc44f0f to your computer and use it in GitHub Desktop.
Save vintprox/4ebb5db85a36668833a0c4f09dc44f0f to your computer and use it in GitHub Desktop.
Guarding commands to whitelisted channels - workaround for discordjs/Commando#34
/**
* ./guards.js
*/
const store = require('./store.js');
exports.notAssigned = async function(msg, channel) {
const assigned = await store.get(channel.id, false);
return !assigned && msg.direct(`I am not assigned to ${channel}. Try another channel.`);
}
/**
* ./commands/game/start.js
*/
const { Command } = require('discord.js-commando');
const { notAssigned } = require('../../guards.js');
module.exports = class StartCommand extends Command {
constructor(client) {
super(client, {
name: 'start',
memberName: 'start',
group: 'game',
description: `Starts new game round.`,
guildOnly: true
});
}
async run(msg) {
const { channel } = msg;
// Guard that restricts the command to whitelisted channels
const g = await notAssigned(msg, channel); if (g) return g;
msg.react('🎉');
return msg.say(`**Round start!**`);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment