![](/img/trans.png)
[英]My Discord bot's mention help command is not working. Can someone help out? (Discord.js, JavaScript)
[英]My Discord bot's /rolemenuremove command isn't working as expected, please help me out
我的 Discord 机器人的/rolemenuremove
命令没有按预期工作。 当我尝试删除菜单中的角色时,它返回一条消息,指出该角色已被删除,但是当我检查菜单时,另一个角色已被删除。 (不是我想要它删除的那个。)
这是该消息的图像:
这是我的命令代码:
const {MessageEmbed, MessageActionRow, MessageSelectMenu} = require('discord.js');
module.exports = {
name: 'rolemenuremove',
description: 'Removes a role from an existing rolemenu.',
options: [
{
name: 'channel',
description: 'The channel in which the rolemenu is.',
type: 'CHANNEL',
required: true
},
{
name: 'messageid',
description: 'The ID of the rolemenu message.',
type: 'STRING',
required: true
},
{
name: 'role',
description: 'The role to remove from the rolemenu.',
type: 'ROLE',
required: true
}
],
async execute(interaction) {
const channel = interaction.options.getChannel('channel')
if (
channel.type !== 'GUILD_TEXT' &&
channel.type !== 'GUILD_NEWS' &&
channel.type !== 'GUILD_NEWS_THREAD' &&
channel.type !== 'GUILD_PUBLIC_THREAD' &&
channel.type !== 'GUILD_PRIVATE_THREAD'
)
return interaction.reply({content: 'That is not a valid channel type.', ephemeral: true});
const messageid = interaction.options.getString('messageid')
const role = interaction.options.getRole('role')
const message = await channel.messages.fetch(messageid, {cache: true, force: true})
if (!message) return interaction.reply('Invalid message ID.')
if (message.author.id !== interaction.client.user.id) return interaction.reply(`Please provide a message sent by <@${interaction.client.user.id}>`)
let row = message.components[0]
if (!row) return interaction.reply('Invalid message.')
const option = [{
label: role.name,
description: `Get the ${role.name} role.`,
value: role.id
}]
let menu = row.components[0]
if (menu) {
if (!menu.options.some(option => option.value === role.id)) {
return interaction.reply({
content: `<@&${option[0].value}> is not a part of this menu.`,
allowedMentions: {
roles: []
},
ephemeral: true
})
}
menu.spliceOptions(menu.options.lastIndexOf(option), 1)
menu.setMaxValues(menu.options.length)
if (menu.opions.length === 0) return interaction.reply('There needs to be at least one role in the menu.')
} else {
return interaction.reply("Invalid message.")
}
await message.edit({
components: [row],
content: message.content
})
await interaction.reply({
content: `Removed <@&${role.id}> from the menu.`, allowedMentions: {roles: []},
ephemeral: true
})
},
};
请帮助我,并提前致谢。 :)
编辑:更新了我的代码并解决了原始问题,但现在menu.spliceOptions
部分不起作用。 编辑 2:更新了menu.spliceOptions
行,仍然无法正常工作
弄清楚了。 这不是代码的问题,而是我测试的角色的问题。 不知何故,该选项被破坏了,并制作了一个全新的菜单来修复它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.