fixes/search command
This commit is contained in:
3 files changed
+98
-8
No files matched your search
@@ -0,0 +1,89 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "search",
|
||||
description: "Search a users inventory",
|
||||
usage: "[user]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
SlashCommand: {
|
||||
options: [
|
||||
{
|
||||
name: "user",
|
||||
description: "user to give item",
|
||||
value: "user",
|
||||
type: 6,
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/QuarksBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send(`You are not allowed to use the bot in this channel.`);
|
||||
}
|
||||
|
||||
let targetUserID = args[0].value.replace('<@!', '').replace('>', '');
|
||||
let targetUserInventory = await client.dbo.collection("inventories").findOne({"inventory.userID":targetUserID}).then(inventory => inventory);
|
||||
let inventory;
|
||||
|
||||
if (!targetUserInventory) {
|
||||
inventory = {
|
||||
userID: interaction.member.user.id,
|
||||
items: [{
|
||||
name: 'Wallet',
|
||||
type: 'wallet',
|
||||
description: '`/inventory wallet` to view wallet',
|
||||
cash: 0.00,
|
||||
ID: {
|
||||
firstname: '',
|
||||
lastname: '',
|
||||
dob: ''
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
// Register inventory for user with item givn
|
||||
let newInventory = new Inventory();
|
||||
newInventory.createInventory(targetUserID);
|
||||
newInventory.addItem(item);
|
||||
newInventory.save()
|
||||
.catch(err => {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(err)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
} else inventory = targetUserInventory.inventory;
|
||||
|
||||
// Display Inventory
|
||||
|
||||
// This lame line of code to get username without ping on discord
|
||||
const User = client.users.cache.get(targetUserID);
|
||||
|
||||
let inventoryEmbed = new MessageEmbed()
|
||||
.setColor(client.config.EmbedColor)
|
||||
.setTitle(`${User.tag.split('#')[0]}'s Inventory`);
|
||||
|
||||
let description = "```";
|
||||
for (let i = 0; i < inventory.items.length; i++) {
|
||||
description += `${i+1}. ${inventory.items[i].name} - ${inventory.items[i].description}\n`;
|
||||
}
|
||||
description += "```";
|
||||
inventoryEmbed.setDescription(description);
|
||||
|
||||
return interaction.send({ embeds: [inventoryEmbed] });
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user