Reactions / Command Replies
Discord.Short offers a lot of cool things you can do with reactions
When you make a command, you can get the output / reply by running a function, lets start off by creating a giveaway command:
new ds.Command({
name: 'giveaway',
async execute({send}) {
send('Hello!');
}
});
we can get the "Hello!"
message by running this function:
new ds.Command({
name: 'giveaway',
async execute({send}) {
send('Hello!');
let hello = await ds.getNextReply(); // here!
}
});
now we have a message object of the reply, although this is not how we are going to make the command, lets react with a party popper
new ds.Command({
name: 'giveaway',
async execute({send}) {
send('Hello!');
let hello = await ds.getNextReply();
hello.react('🎉');
}
});
When we run the !giveaway
command, we will get this:
This is cool, but we want something to actually happen when we react to the message, so lets run this function
new ds.Command({
name: 'giveaway',
async execute({send}) {
send('Hello!');
let hello = await ds.getNextReply();
// here!
ds.reactEvent(hello, '🎉', function({arguments}) {
// args
});
}
});
where the function says arguments
you can add any of these:
user
- the person who reacted
channel
- the channel the message that was reacted to was in
message
- the message that was reacted to
send()
- send a message in the channel where the reaction was
so lets make it send a message whenever someone reacts:
new ds.Command({
name: 'giveaway',
async execute({send}) {
send('Hello!');
let hello = await ds.getNextReply();
ds.reactEvent(hello, '🎉', function({send, user}) {
send(`${user.username} reacted with 🎉`); // here!
});
}
});
now when we run the command and react, it should look like this:
then, we can make the giveaway work. I have a simple premade example, so ill just show it here:
new ds.Command({
name: 'giveaway',
async execute({send, author, args}) {
send(new MessageEmbed({
title: '🎉 Giveaway!',
description: `<@${author.id}> is giving away **${args[0]}**`,
footer: {
text: 'to enter, react to this message with 🎉'
},
color: 'BLUE'
}));
let players = [];
ds.reactEvent(await ds.getNextReply(), '🎉', function({user}) {
players.push(user);
});
setTimeout(function() {
let rng = Math.floor(Math.random() * (players.length - 1));
send(`Congrats! 🎉\n> <@${players[rng].id}> won **${args[0]}**`);
}, Number(args[1]) * 1000);
}
});
now if we run, !giveaway example 10
it will create a giveaway for "example" and will end in 10 seconds
after the giveaway, it will look something like this:
Similarly to ds.reactEvent();
you can see when someone un-reacts, it has the same syntax:
ds.unreactEvent(await ds.getNextReply(), '🎉', function({arguments}) {
// args
});