Discord.JS voiceStateUpdate newState chanelID 为空
Discord.JS voiceStateUpdate newState chanelID is null
在我的 discord 机器人中,当用户加入服务器时应该播放声音。
播放和其他一切正常,但触发 voiceStateUpdate 时创建的 newState 对象 不包含 channelID。
当用户在频道之间切换时我会得到一个频道 ID,但从外部加入时不会。
我正在使用 Discord.js v13.0
module.exports = (oldState, newState) => {
console.log(newState.channelID);
};
事件处理:
const evt = require(`./events/${file}`);
let evtName = file.split(".")[0];
console.log(`Loaded event '${evtName}'`);
client.on(evtName, evt.bind(null, client));
连接外部的控制台输出:
channelID: null
控制台输出通道-更改:
channelID: '6xxxxxxxxxxxxxxxxx8'
您没有在模块导出中将 client
作为参数传递,因此我猜测您的 oldState
具有客户端值,而 newState
具有实际的 oldState 值。尝试将 client
添加到 module.exports
.
的开头
module.exports = (client, oldState, newState) => {
// Stuff
}
不确定这是否正确,因为您没有提供任何事件处理代码。
您需要这样输入 channelID
:channelId
module.exports = (oldState, newState) => {
console.log(newState.channelId);
};
检查:https://discord.js.org/#/docs/discord.js/stable/class/VoiceState?scrollTo=channelId
在我的 discord 机器人中,当用户加入服务器时应该播放声音。
播放和其他一切正常,但触发 voiceStateUpdate 时创建的 newState 对象 不包含 channelID。
当用户在频道之间切换时我会得到一个频道 ID,但从外部加入时不会。
我正在使用 Discord.js v13.0
module.exports = (oldState, newState) => {
console.log(newState.channelID);
};
事件处理:
const evt = require(`./events/${file}`);
let evtName = file.split(".")[0];
console.log(`Loaded event '${evtName}'`);
client.on(evtName, evt.bind(null, client));
连接外部的控制台输出:
channelID: null
控制台输出通道-更改:
channelID: '6xxxxxxxxxxxxxxxxx8'
您没有在模块导出中将 client
作为参数传递,因此我猜测您的 oldState
具有客户端值,而 newState
具有实际的 oldState 值。尝试将 client
添加到 module.exports
.
module.exports = (client, oldState, newState) => {
// Stuff
}
不确定这是否正确,因为您没有提供任何事件处理代码。
您需要这样输入 channelID
:channelId
module.exports = (oldState, newState) => {
console.log(newState.channelId);
};
检查:https://discord.js.org/#/docs/discord.js/stable/class/VoiceState?scrollTo=channelId