ras
ras
Explore posts from servers
DIAdiscord.js - Imagine a boo! 👻
Created by ras on 2/1/2024 in #djs-questions
What's the preferred way of accessing collections in a command file?
Currently I have something like this
try {
if (interaction.commandName === 'user') {
await command.execute(interaction, currency) // Currency is a Collection of user ids and balances
} else {
await command.execute(interaction)
}
} catch (error) {
console.error(error)
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true })
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true })
}
}
try {
if (interaction.commandName === 'user') {
await command.execute(interaction, currency) // Currency is a Collection of user ids and balances
} else {
await command.execute(interaction)
}
} catch (error) {
console.error(error)
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true })
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true })
}
}
Where I just send the collections along when I execute the command from the main file, depending on the command but this feels a bit hacky, as does having a separate file exporting collections. What should I be doing? Thanks! npm list discord.js: 14.14.1 node -v: v21.1.0
16 replies