我如何使用菜单discordjs从我的语音通道断开用户



我想断开指定用户的连接点击他的用户名,这是我的代码:

options = [];
let perms = channel.members.map(c => c.user.tag)

for (let i = 0; i < perms.length; i++) {

options.push({
label: `${perms[i]}`,
value: `${i}`})     
}
const Select = new MessageSelectMenu()
.setCustomId(`disconnect`)
.setPlaceholder(`Members`)
.addOptions(options)
.setMaxValues(1);
const menu = new MessageActionRow()
.addComponents(Select);
const embed = new MessageEmbed()
.setColor("BLUE" )
.setDescription("Please select the user from the dropdown to disconnect.");
interaction.reply({
embeds: [embed],
components: [menu], ephemeral: true
})          


}

Discord.js v13 .

注意:我正在寻找如何通过选择他们的用户名来断开用户与vc的连接。Ty。

我更改了第一部分,但如果您愿意,您可以使用您的方式(您必须使用不同的方式获得member2disconnect)。这样似乎更容易,因为值将是用户的id而不是整数。

const embed = new MessageEmbed()
.setColor("BLUE")
.setDescription("Please select the user from the dropdown to disconnect.");
const menu = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId(`disconnect`)
.setPlaceholder(`Members`)
.setMaxValues(1),
);
client.channels.cache.get(interaction.member.voice.channelId).members.forEach(member => {
menu.components[0].addOptions({
label: `${member.user.tag}`,
value: member.user.id,
});
});
return interaction.reply({
embeds: [embed],
components: [menu],
});

下一部分放入interactionCreate监听器

client.on('interactionCreate', async interaction => {
if (interaction.isSelectMenu()) {
const selection = interaction.customId;
if (selection == 'disconnect') {
const member2disconnect = interaction.guild.members.cache.get(interaction.values[0]);
member2disconnect.voice.disconnect();
return interaction.message.edit({
content: `${member2disconnect} has been kicked from the VC.`,
embeds: [],
components: [],
ephemeral: true,
});
}
}
});

相关内容

  • 没有找到相关文章

最新更新