Flotty
Flotty
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
Omg it worked ty @gwapes
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
:blobreachReverse:
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
Tyvm
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
I had copied the command handler from a YouTube video, would I need to make a new file with the autocomplete handler or just add something in the old file?
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
I don't get what you mean
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
:pikaOh:
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
Had to split it into 2 parts because I don't have nitro for longer messages lmao
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
async autocomplete(interaction) {
const focusedOption = interaction.options.getFocused(true);
const allItems = [
...items.runes.playstyle,
...items.runes.elemental,
...Object.keys(items.usables),
];

let choices = allItems.filter(item => item.toLowerCase().includes(focusedOption.value.toLowerCase()));

await interaction.respond(
choices.map(choice => ({ name: choice, value: choice }))
);
}
}
async autocomplete(interaction) {
const focusedOption = interaction.options.getFocused(true);
const allItems = [
...items.runes.playstyle,
...items.runes.elemental,
...Object.keys(items.usables),
];

let choices = allItems.filter(item => item.toLowerCase().includes(focusedOption.value.toLowerCase()));

await interaction.respond(
choices.map(choice => ({ name: choice, value: choice }))
);
}
}
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
module.exports = {
data: new SlashCommandBuilder()
.setName('adminitemgive')
.setDescription('Give an item to a user')
.addUserOption(option =>
option.setName('user')
.setDescription('User to give the item to')
.setRequired(true)
)
.addStringOption(option =>
option.setName('item')
.setDescription('Item to give')
.setRequired(true)
.setAutocomplete(true)
)
.addIntegerOption(option =>
option.setName('quantity')
.setDescription('Quantity of the item to give')
.setRequired(true)
.setMinValue(1)
.setMaxValue(100)
),

async execute(interaction) {
if (interaction.user.id !== YOUR_USER_ID) {
return interaction.reply({ content: 'You do not have permission to use this command.', flags: 64 });
}

const user = interaction.options.getUser('user');
const itemId = interaction.options.getString('item');
const quantity = interaction.options.getInteger('quantity');

let inventory = await InventoryModel.findOne({ userId: user.id });
if (!inventory) {
inventory = new InventoryModel({ userId: user.id, items: [], equippedRunes: { playstyle: {}, elemental: [] } });
await inventory.save();
}

const allItems = [
...items.runes.playstyle,
...items.runes.elemental,
...Object.keys(items.usables),
];

const item = allItems.find(i => i.toLowerCase() === itemId.toLowerCase());
if (!item) {
return interaction.reply({ content: 'Item not found.', flags: 64 });
}

await inventory.addItem(itemId, quantity);
return interaction.reply({ content: `${quantity}x ${itemId} have been given to ${user.username}.`, flags: 64 });
},
module.exports = {
data: new SlashCommandBuilder()
.setName('adminitemgive')
.setDescription('Give an item to a user')
.addUserOption(option =>
option.setName('user')
.setDescription('User to give the item to')
.setRequired(true)
)
.addStringOption(option =>
option.setName('item')
.setDescription('Item to give')
.setRequired(true)
.setAutocomplete(true)
)
.addIntegerOption(option =>
option.setName('quantity')
.setDescription('Quantity of the item to give')
.setRequired(true)
.setMinValue(1)
.setMaxValue(100)
),

async execute(interaction) {
if (interaction.user.id !== YOUR_USER_ID) {
return interaction.reply({ content: 'You do not have permission to use this command.', flags: 64 });
}

const user = interaction.options.getUser('user');
const itemId = interaction.options.getString('item');
const quantity = interaction.options.getInteger('quantity');

let inventory = await InventoryModel.findOne({ userId: user.id });
if (!inventory) {
inventory = new InventoryModel({ userId: user.id, items: [], equippedRunes: { playstyle: {}, elemental: [] } });
await inventory.save();
}

const allItems = [
...items.runes.playstyle,
...items.runes.elemental,
...Object.keys(items.usables),
];

const item = allItems.find(i => i.toLowerCase() === itemId.toLowerCase());
if (!item) {
return interaction.reply({ content: 'Item not found.', flags: 64 });
}

await inventory.addItem(itemId, quantity);
return interaction.reply({ content: `${quantity}x ${itemId} have been given to ${user.username}.`, flags: 64 });
},
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
Wait I'll send the full command (it's actually two different commands with the same issue but I assume if I fix one I should be able to fix the other)
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
No description
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
async autocomplete(interaction) {
const focusedOption = interaction.options.getFocused(true);

if (focusedOption.name === 'item') {
const user = interaction.user;
const inventory = await InventoryModel.findOne({ userId: user.id });

if (!inventory) {
return interaction.respond([]);
}

const usableItems = inventory.items.filter(item =>
Object.keys(items.usables).includes(item.itemId) && item.quantity > 0
);

const suggestions = usableItems.map(item => ({
name: item.itemId,
value: item.itemId
}));

await interaction.respond(suggestions);
}
}
};
async autocomplete(interaction) {
const focusedOption = interaction.options.getFocused(true);

if (focusedOption.name === 'item') {
const user = interaction.user;
const inventory = await InventoryModel.findOne({ userId: user.id });

if (!inventory) {
return interaction.respond([]);
}

const usableItems = inventory.items.filter(item =>
Object.keys(items.usables).includes(item.itemId) && item.quantity > 0
);

const suggestions = usableItems.map(item => ({
name: item.itemId,
value: item.itemId
}));

await interaction.respond(suggestions);
}
}
};
22 replies
DIAdiscord.js - Imagine an app
Created by Flotty on 1/30/2025 in #djs-questions
Issue with "custom" autocomplete
v22.13.1, it won't show the discord.js when running the command you sent tho
22 replies