its*_*ara 3 javascript node.js discord.js
我正在尝试发出一个命令,将语音通道中的所有成员(该命令的作者所在的通道)移动到另一个通道(在参数中给出)。但我有一个问题,VoiceState 不会一致更新,连接和更改频道是可以的,但如果与语音频道断开连接,机器人仍然会看到我的 voiceState,就像我已连接一样。
//The command file
const Discord= require('discord.js');
const {SlashCommandBuilder} = require("@discordjs/builders");
module.exports = {
data: new SlashCommandBuilder()
.setName('move')
.setDescription('Move all the members to a specific voice channel')
.addChannelOption(option =>
option.setName('voicechannel')
.setDescription('The voice channel to move everyone in')
.setRequired(true)),
async execute(interaction) {
const author = interaction.member
const voice = author.guild.voiceStates.cache
console.log(voice.get(author.id))
console.log(interaction.options.get('voicechannel').channel.id)
if (voice.get(author.id) == undefined || voice.get(author.id) == null){
await interaction.reply({content : 'You need to be in a voice channel first', ephemeral: true})
} else if (interaction.options.get('voicechannel').channel.id == voice.get(author.id).channelId) {
await interaction.reply({content : 'Can\'t move to the same channel', ephemeral: true})
} else {
await interaction.reply({content : 'ok', ephemeral: true})
///TO IMPLEMENT CODE
}
},
};
Run Code Online (Sandbox Code Playgroud)
//my client constructor
const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] });
Run Code Online (Sandbox Code Playgroud)
小智 5
确保您对客户端构建有明确的GUILD_VOICE_STATES 意图。
const client: Client = new discord.Client({
intents: 641,
});
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的问题,语音通道的状态是在机器人启动时设置的,但永远不会更新。
我使用这个意图计算器来轻松包含所有意图。
特别查看“音乐机器人”预设 (641)。
| 归档时间: |
|
| 查看次数: |
2278 次 |
| 最近记录: |