Created
August 30, 2019 19:08
-
-
Save vintprox/4ebb5db85a36668833a0c4f09dc44f0f to your computer and use it in GitHub Desktop.
Guarding commands to whitelisted channels - workaround for discordjs/Commando#34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ./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.`); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ./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