free-code
Version:
Makes free code for discord.js command/bots
44 lines (41 loc) • 1.72 kB
JavaScript
const {
Client,
Message,
MessageEmbed
} = require('discord.js');
require('discord-reply');
const rps = ['scissors','rock', 'paper'];
const res = ['Scissors :v:','Rock :fist:', 'Paper :raised_hand:'];
module.exports = {
name: 'rps',
usage: 'rps <rock | paper | scissors>',
description: 'Play a game of rock–paper–scissors against the bot!',
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
let userChoice;
if (args.length) userChoice = args[0].toLowerCase();
if (!rps.includes(userChoice))
return message.lineReply('Please enter rock, paper, or scissors');
userChoice = rps.indexOf(userChoice);
const botChoice = Math.floor(Math.random() * 3);
let result;
if (userChoice === botChoice) result = 'It\'s a draw!';
else if (botChoice > userChoice || botChoice === 0 && userChoice === 2) result = `**${client.user.username}** wins!`;
else result = `**${message.member.displayName}** wins!`;
const embed = new MessageEmbed()
.setTitle(`${message.member.displayName} vs. ${client.user.username}`)
.addField('Your Choice:', res[userChoice], true)
.addField(`${client.user.username}\'s Choice`, res[botChoice], true)
.addField('Result', result, true)
.setFooter(message.member.displayName, message.author.displayAvatarURL({
dynamic: true
}))
.setTimestamp()
.setColor(message.guild.me.displayHexColor);
message.channel.send(embed);
}
}