this is a pretty much simple snippet you can add to your economy system i advice you to use this basic economy api, https://autocode.com/app/starsblaster/economy-app/, all you need to do is change the prefix to whatever you want in the endpoint of the snippet, and also i recommend that you use the same gsheets suggest by the economy app, there should be that, and that should be all have fun!!, ping me on autocode LaRose#8695, if you have an error, or a suggestion.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
module.exports = async (event, context) => {
let items = ['Heads', 'Tails'];
let random = items[Math.floor(Math.random() * items.length)];
let text = event.content.replace('?coinflip ', '');
//event.content.split(" ");
console.log(text);
let moneyDatabase = await lib.googlesheets.query['@0.3.0'].distinct({
range: `A:G`,
bounds: `FIRST_EMPTY_ROW`,
where: [
{
user_id__is: event.author.id,
},
],
field: `money`,
});
let message = ['you lost it all :(', `you won **$${text}**`];
let rand = message[Math.floor(Math.random() * message.length)];
let sleep = async (ms) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms || 0);
});
};
if (!moneyDatabase.distinct.values[0]) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `You don't have a bank account, please make one!`,
});
return;
} else if (!text[1]) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `You have to insert a number to give them`,
});
} else if (parseInt(text[1]) > parseInt(moneyDatabase.distinct.values[0])) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `You don't even have that much money to use`,
});
} else if (parseInt(text[1]) < 0) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `Money can't be negative`,
});
} else if (text[1].match(/\D/gi)) {
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `You can only type digits here`,
});
} else {
let coinmessage = await lib.discord.channels['@0.3.0'].messages.create({
channel_id: event.channel_id,
content: `${context.params.event.author.username} spent **$${text}** and chose **${random}**`,
});
await sleep(1000);
await lib.discord.channels['@0.3.0'].messages.update({
message_id: coinmessage.id,
channel_id: event.channel_id,
content: `| and ${rand}`,
});
await lib.googlesheets.query['@0.3.0'].update({
range: `A:G`,
bounds: 'FIRST_EMPTY_ROW',
where: [
{
user_id: event.author.id,
},
],
fields: {
money: parseInt(moneyDatabase.distinct.values[0]) + parseInt(text[1]),
},
});
}
};