discord - 试图制作一个机器人来计算语音频道中的成员
问题描述
如果认为我问的是愚蠢的,请不要发表评论。我对此完全陌生。我尝试搜索解决方案,但找不到有用的解决方案或 discord.js 中的菜鸟可以理解的解决方案。提前谢谢你的帮助!
const express = require ("express")
var app = require('express')();
app.get("/", (req, res) => {
res.send("hello hell!")
})
app.listen(3000, () => {
console.log("Project is ready")
})
let Discord = require("discord.js")
let client = new Discord.Client()
client.on('voiceStateUpdate', (oldVoiceState, newVoiceState) => {
let newUserChannel = newVoiceState.voiceChannel
let oldUserChannel = oldVoiceState.voiceChannel
if(oldUserChannel === undefined && newUserChannel !== undefined) {
// User Joins a voice channel
console.log(client.voiceConnections.size)
} else if(newUserChannel === undefined){
// User leaves a voice channel
console.log(client.voiceConnections.size)
}
})
client.login("token")
repl.it 某人加入时的结果 Project is ready
console.log(client.voiceConnections.size)
^
TypeError: Cannot read property 'size' of undefined
at Client.<anonymous> (/home/runner/VCC-Bot/index.js:30:37)
at Client.emit (events.js:315:20)
at Client.EventEmitter.emit (domain.js:483:12)
at VoiceStateUpdate.handle (/home/runner/VCC-Bot/node_modules/discord.js/src/client/actions/VoiceStateUpdate.js:40:14)
at Object.module.exports [as VOICE_STATE_UPDATE] (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/handlers/VOICE_STATE_UPDATE.js:4:35)
at WebSocketManager.handlePacket (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/VCC-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/VCC-Bot/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
解决方案
不知道我在这里是否为时已晚,但你需要给机器人它的意图。您可以像这样添加意图:
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILD_VOICE_STATES],
});
推荐阅读
- r - 从 Edag 的 8-k 和 10-k 文件中刮取“项目”
- r - kruskal.test.default(list(vec1, vec2)) 中的错误:所有组必须包含数据
- apache - 如何在安装过程中将第三方库与 httpd-2.4.46 链接?
- export-to-csv - 将 featureCollections 集合导出为 CSV?
- python - Python selenium 代码不适用于我的电脑上的选项
- python - 如何在pygame中横向反转图像?
- jquery - jQuery重复每个功能,编写更少的代码
- angular - 使用 CDK/Overlay 创建附加到元素的小对话框
- lstm - 一对多 LSTM
- r - 如何在 R 数据框中对具有多个可能输出的函数进行矢量化