Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
msg.channel.startTyping();
const authorBalance = await database.balances.get(msg.author.id);
// Amount checking
if (amount > authorBalance) {
return msg.reply(
`You need to have at least \`${amount.toLocaleString()}\` ${
config.currency.plural
}. Your balance is \`${authorBalance}\`.`
);
}
try {
await Discoin.currencies.getOne(currency);
} catch (error) {
return msg.reply("An error occurred. Are you sure that currency exists");
}
const transaction = await discoin.transactions
.create({ to: currency, amount, user: msg.author.id })
.catch(() => msg.reply("An error occurred. Maybe Discoin is offline? Try checking their support server."));
// Remove oats from author
await database.balances.decrease(msg.author.id, amount);
return msg.replyEmbed({
title: "Conversion Successful",
url: `https://dash.discoin.zws.im/#/transactions/${transaction.id}/show`,
color: 0x4caf50,
timestamp: transaction.timestamp,
async exec(msg) {
try {
msg.channel.startTyping();
const currencies = await Discoin.currencies.getMany();
const embed = new MessageEmbed({
title: "Discoin Conversion Rates",
url: "https://dash.discoin.zws.im/#/currencies"
});
const oatsCurrency = currencies.find(currency => currency.id === "OAT");
currencies.forEach(currency => {
embed.addField(
currency.name,
stripIndents`
Currency code: ${currency.id}
Value in Discoin D$: ${currency.value.toLocaleString()}
Value in oats: ${(currency.value / oatsCurrency.value).toLocaleString()}`
);