35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
//Boring init stuff
|
|
const { SlashCommandBuilder } = require('discord.js');
|
|
const { Users } = require('../../dbObjects.js');
|
|
const helpers = require('../../helpers.js');
|
|
|
|
module.exports = {
|
|
//Creates the slash command
|
|
cooldown: 1800,
|
|
data: new SlashCommandBuilder()
|
|
.setName('gamble')
|
|
.setDescription('bet a certain amount of ospCoin, and either win or lose that amount.')
|
|
.addIntegerOption(option =>
|
|
option
|
|
.setName('amount')
|
|
.setDescription('Amount of ospCoin to bet')
|
|
.setRequired(true)),
|
|
//Executes said slash command
|
|
async execute(interaction) {
|
|
const amount = interaction.options.getInteger('amount') ?? 0;
|
|
const target = interaction.user;
|
|
const id = target.id;
|
|
if(amount <= helpers.getBalance(id) && amount > 0) {
|
|
if(Boolean(Math.round(Math.random()))) {
|
|
helpers.addBalance(id, amount);
|
|
await interaction.reply(`You won **${amount}** ospCoin!`);
|
|
} else {
|
|
helpers.addBalance(id, -amount);
|
|
await interaction.reply(`You lost **${amount}** ospCoin :<`);
|
|
}
|
|
} else {
|
|
await interaction.reply(`Invalid amount!`);
|
|
}
|
|
},
|
|
};
|