"cannot find name 'member'"



我正在Discord.js v13中编写一个审核机器人,对于静音、踢、警告和禁止命令,我需要检查用户权限。然而,我的代码无法编译:;找不到名称"member";。我已经检查了文档,并使用了与所示完全相同的方法。

这是我的代码,错误在第67行。我已经用TypeScript写了这篇文章,但这对错误没有任何影响。

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:__**nn**/ping** Shows the bot's latency.n**/help** Guess what this one does :thinking:n**/cases** Allows non-moderators to check their punishment history.nn**/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);```

根据文档,interaction对象应该具有member属性。尝试使用interaction.memberconst { commandName, options, member } = interaction;获取

最新更新