I'm coding a moderation bot in Discord.js v13, and for the mute, kick, warn and ban commands I need to check user permissions. However, my code fails to compile: "Cannot find name 'member'". I've checked the documentation and I've used the exact same method shown.
Here is my code, the error is in line 67. I've written this in TypeScript, however this should not have any effect on the error.
import { User, Permissions } from "discord.js";
import { SlashCommandBuilder } from "@discordjs/builders";
import mongoose from "mongoose";
import punishmentSchema from "./schemas/punishment-schema";
const config = require("./config.json");
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MEMBERS
]
});
client.on("ready", async () => {
console.log("Ready for your orders, boss!");
await mongoose.connect(`${config.mongodb_uri}`, {
keepAlive: true,
});
const guildId = "868810640913989653";
const guild = client.guilds.cache.get(guildId);
let commands;
if(guild) {
commands = guild.commands;
} else {
commands = client.application?.commands;
}
commands?.create({
name: "ping",
description: "Shows the bot's latency.",
});
commands?.create({
name: "help",
description: "Lists all commands and shows their usage.",
});
commands?.create({
name: "mute",
description: "Allows moderators to mute users.",
});
commands?.create({
name: "ban",
description: "Allows moderators to ban users.",
});
});
client.on("interactionCreate", async (interaction) => {
if(!interaction.isCommand()) return;
const { commandName, options } = interaction;
if(commandName === "ping") {
interaction.reply({
content: `Current latency: \`\`${client.ws.ping}ms\`\``,
ephemeral: false,
})
} else if(commandName === "help") {
interaction.reply({
content: `**__List of available commands:__**\n\n**/ping** Shows the bot's latency.\n**/help** Guess what this one does :thinking:\n**/cases** Allows non-moderators to check their punishment history.\n\n**/warn {user} [reason]** Applies a warning to a user. :shield:\n**/kick {user} [reason]** Kicks a user from the server. :shield:\n**/mute {user} [duration] [reason]** Kicks a user from the server. :shield:\n**/mute {user} [duration] [reason]** Mutes a user. :shield:\n**/ban {user} [duration] [reason]** Bans a user from the server. :shield:\n**/history {user}** Shows the punishment history of a user. :shield:`,
ephemeral: false,
})
} else if(commandName === "mute") {
if (member.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) {
console.log('test if kick');
}
} else if(commandName === "mute") {
}
});
client.login(config.token);```
CodePudding user response:
According to docs, interaction
object, should have member
property. Try to get it with interaction.member
or const { commandName, options, member } = interaction;
CodePudding user response:
I cannot see where do you have declared "member". Not even in the imports, maybe something is missing?