This is a slash command that will do little battles for you! It stops people from fighting themselves or bots. Thanks to CesarHvl for helping me!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); // <-- authenticates you with the API standard library
// This chunk of code is REQUIRED for the else if and else embed's to work as it grabs the user data for avatar's
const user_id = context.params.event.member.user.id;
const avatarURL = context.params.event.member.user.avatar
? `https://cdn.discordapp.com/avatars/${user_id}/${context.params.event.member.user.avatar}.png?size=256`
: `https://cdn.discordapp.com/embed/avatars/${parseInt(context.params.event.member.user.discriminator, 10) % 5}.png`;
const ID = context.params.event.data.options.length
? context.params.event.data.options[0].value
: user_id;
const member = await lib.discord.guilds['@0.1.0'].members.retrieve({
user_id: ID,
guild_id: context.params.event.guild_id,
});
// If member is bot OR user_id matches input ID: msg the user that they can't fight themselves/bots
if (member.user.bot || user_id === ID) {
return await lib.discord.channels['@0.3.2'].messages.create({
channel_id: context.params.event.channel_id,
content: '',
embeds: [
{
type: 'rich',
description: `<@${user_id}> you can't fight yourself/bots.`,
color: 000000,
},
],
});
}
// This chunk of code is the logic begind the "battle" and the results
let Player1 = Math.floor(Math.random() * 15);
let Player2 = Math.floor(Math.random() * 15);
if (Player1 == Player2) {
return await lib.discord.channels['@0.3.2'].messages.create({
channel_id: context.params.event.channel_id,
content: '',
embeds: [
{
type: 'rich',
title: '⚔️ **__Death-Battle__** ⚔️',
description: `No one won! It was a Draw.`,
color: 000000,
},
],
});
} else if (Player1 > Player2) {
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: context.params.event.channel_id,
content: '',
embeds: [
{
color: 000000,
description: '⚔️ **__Death-Battle__** ⚔️',
thumbnail: {
url: avatarURL,
},
fields: [
{
name: `Winner:`,
value: `<@${user_id}>`,
},
{
name: `Loser:`,
value: `<@${ID}>`,
},
],
},
],
});
} else {
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: context.params.event.channel_id,
content: '',
embeds: [
{
color: 000000,
description: '⚔️ **__Death-Battle__** ⚔️',
thumbnail: {
url: member.user.avatar_url,
},
fields: [
{
name: `Winner:`,
value: `<@${ID}>`,
},
{
name: `Loser:`,
value: `<@${user_id}>`,
},
],
},
],
});
}