我尝试在Discord.js v14上执行清除命令,但它一直显示以下错误:
TypeError: Cannot read properties of undefined (reading 'has')
下面是代码:
const { SlashCommandBuilder, Embed, EmbedBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('clear')
.setDescription("Delete messages")
.addIntegerOption(option => option.setName('messages').setDescription('Messages to delete').setRequired(true)),
async execute(interaction) {
const messages = interaction.options.getInteger('messages');
if(!interaction.user.id.permissions.has(PermissionsBitField.Flags.ManageMessages)){
interaction.reply({ content: "You can't send messages!", ephemeral: true} )
}
}
}
1条答案
按热度按时间dsf9zpds1#
interaction.user.id
提供了一个字符串,其中包含运行斜杠命令的用户的ID。要检查权限,您需要用户的GuildMember
数据,您可以使用interaction.member
访问该数据。因此,您的修复代码如下所示: