Real_IceyDev

Discord.js - Part 5 | Update Items in Inventory

Jan 7th, 2022 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Part 5 of 7 for inventory command. This is how to update an item from list. Part 6:
  2.  
  3. const command5 = {};
  4. command5.name = 'update';
  5. command5.description = 'updates an item in the database';
  6. command5.usage = '<item> <price>';
  7. command5.category = 'database';
  8. command5.useDatabase = true;
  9. command5.useApi = false;
  10. command5.execute = async(bot, message, args) => {
  11.     if (!message.member.hasPermission('ADMINISTRATOR')) return message.channel.send('You do not have permission to use this command!');
  12.     if (args.length != 2) return message.channel.send('You have not provided the correct amount of arguments!');
  13.     let item = args[0];
  14.     let price = args[1];
  15.     if (isNaN(price)) return message.channel.send('The price is not a number!');
  16.     let query = `UPDATE items SET price = ${price} WHERE item = '${item}'`;
  17.     bot.database.execute(query).then(() => {
  18.         // send a success message
  19.         message.channel.send('The item has been updated!');
  20.     }).catch(() => {
  21.         // send an error message
  22.         message.channel.send('An error has occured!');
  23.     });
  24. }
Add Comment
Please, Sign In to add comment