Tissemyren
DIAdiscord.js - Imagine an app
•Created by Tissemyren on 4/6/2024 in #djs-questions
Maybe this isn't discord.js but yesyes
5 replies
DIAdiscord.js - Imagine an app
•Created by Tissemyren on 2/26/2024 in #djs-questions
I don't really understand the registering slash commands part of the guide
It says to put this codeinside a
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');
const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');
const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
deploy-commands.js
script11 replies
DIAdiscord.js - Imagine an app
•Created by Tissemyren on 2/25/2024 in #djs-questions
Why does it just say "application didn't respond"?
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const Utils = require('../../utils');
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a player from the server')
.addUserOption(option =>
option.setName('user')
.setDescription('The user to ban')
.setRequired(true))
.addStringOption(option =>
option.setName('time')
.setDescription('The time to ban the user for'))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason to ban the user for')),
async execute(interaction) {
const user = interaction.options.getUser('user');
const time = interaction.options.getUser('time');
const reason = interaction.options.getUser('reason');
const channel = await client.channels.fetch("1198299044582281216", { force: true });
const embed = new EmbedBuilder()
embed.setTitle("test")
await interaction.reply({ embeds: [embed] })
},
};
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const Utils = require('../../utils');
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a player from the server')
.addUserOption(option =>
option.setName('user')
.setDescription('The user to ban')
.setRequired(true))
.addStringOption(option =>
option.setName('time')
.setDescription('The time to ban the user for'))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason to ban the user for')),
async execute(interaction) {
const user = interaction.options.getUser('user');
const time = interaction.options.getUser('time');
const reason = interaction.options.getUser('reason');
const channel = await client.channels.fetch("1198299044582281216", { force: true });
const embed = new EmbedBuilder()
embed.setTitle("test")
await interaction.reply({ embeds: [embed] })
},
};
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
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 });
}
}
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
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 });
}
}
});
No command matching ban was found.
in the console.19 replies
DIAdiscord.js - Imagine an app
•Created by Tissemyren on 2/24/2024 in #djs-questions
TypeError: Cannot read properties of undefined (reading 'get')
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const Utils = require('../../utils');
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a player from the server')
.addUserOption(option =>
option.setName('user')
.setDescription('The user to ban')
.setRequired(true))
.addStringOption(option =>
option.setName('time')
.setDescription('The time to ban the user for'))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason to ban the user for')),
async execute(interaction) {
const user = interaction.options.getUser('user');
const time = interaction.options.getUser('time');
const reason = interaction.options.getUser('reason');
const channel = await client.channels.fetch("1198299044582281216", { force: true });
const embed = new EmbedBuilder()
embed.setTitle(channel.name)
await interaction.reply({ embeds: [embed] })
},
};
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const Utils = require('../../utils');
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a player from the server')
.addUserOption(option =>
option.setName('user')
.setDescription('The user to ban')
.setRequired(true))
.addStringOption(option =>
option.setName('time')
.setDescription('The time to ban the user for'))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason to ban the user for')),
async execute(interaction) {
const user = interaction.options.getUser('user');
const time = interaction.options.getUser('time');
const reason = interaction.options.getUser('reason');
const channel = await client.channels.fetch("1198299044582281216", { force: true });
const embed = new EmbedBuilder()
embed.setTitle(channel.name)
await interaction.reply({ embeds: [embed] })
},
};
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
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 });
}
}
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
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 });
}
}
});
6 replies
DIAdiscord.js - Imagine an app
•Created by Tissemyren on 2/24/2024 in #djs-questions
Doesn't fetch the channel, why?
const channel = client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);
const channel = client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);
13 replies
DIAdiscord.js - Imagine an app
•Created by Tissemyren on 2/24/2024 in #djs-questions
It doesn't fetch the channel
const { EmbedBuilder } = require("discord.js");
module.exports = async (client) => {
console.log("Loaded: Message Logger");
try {
const channel = await client.channels.fetch(1159494066673815562);
} catch(e) {
console.log("Error:");
console.log(String(e.stack).yellow);
}
};
const { EmbedBuilder } = require("discord.js");
module.exports = async (client) => {
console.log("Loaded: Message Logger");
try {
const channel = await client.channels.fetch(1159494066673815562);
} catch(e) {
console.log("Error:");
console.log(String(e.stack).yellow);
}
};
undefined
4 replies
DIAdiscord.js - Imagine an app
•Created by Tissemyren on 12/31/2022 in #djs-questions
button cooldown
how would i make a cooldown on a button? I found something on google, but it looks like it's a cooldown for all buttons, i just want a cooldown for a specific button (it should not be a global cooldown, but just a cooldown per user)
12 replies