我如何使用菜单discordjs断开用户与我的语音通道的连接
How can i disconnect a user from my voice channel using menu 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,
});
}
}
});
所以我试图断开我语音频道上的指定用户的连接,点击他的用户名,这是我的代码:
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,
});
}
}
});