$ JJ
DIAdiscord.js - Imagine an app
•Created by $ JJ on 7/13/2024 in #djs-questions
Missing access error
I'm trying to make a warn command, I don't know why it's saying missing access. The only thing the bot fetches is guild ID.
const { Events, Client, GatewayIntentBits, ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder, EmbedBuilder, SelectMenuDefaultValueType, Embed } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const Warning = require('../../Schemas/warning');
module.exports = {
data: new SlashCommandBuilder()
.setName('warn')
.setDescription('Warn a user')
.addUserOption(option => option.setName('user').setDescription('The user to warn').setRequired(true))
.addStringOption(option => option.setName('reason').setDescription('The reason for the warning').setRequired(true)),
async execute(interaction) {
const userId = interaction.options.getUser('user').id;
const reason = interaction.options.getString('reason');
const moderatorId = interaction.user.id;
const guildId = interaction.guildId;
let warning = await Warning.findOne({ userId, guildId });
if (!warning) {
warning = new Warning({
userId,
guildId,
warnings: []
});
}
warning.warnings.push({ moderatorId, reason });
await warning.save();
await interaction.reply(`User has been warned for: ${reason}`);
}
};
const { Events, Client, GatewayIntentBits, ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder, EmbedBuilder, SelectMenuDefaultValueType, Embed } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const Warning = require('../../Schemas/warning');
module.exports = {
data: new SlashCommandBuilder()
.setName('warn')
.setDescription('Warn a user')
.addUserOption(option => option.setName('user').setDescription('The user to warn').setRequired(true))
.addStringOption(option => option.setName('reason').setDescription('The reason for the warning').setRequired(true)),
async execute(interaction) {
const userId = interaction.options.getUser('user').id;
const reason = interaction.options.getString('reason');
const moderatorId = interaction.user.id;
const guildId = interaction.guildId;
let warning = await Warning.findOne({ userId, guildId });
if (!warning) {
warning = new Warning({
userId,
guildId,
warnings: []
});
}
warning.warnings.push({ moderatorId, reason });
await warning.save();
await interaction.reply(`User has been warned for: ${reason}`);
}
};
27 replies