Discord.js v13 如何查看vc 某人在哪个?
Discord.js v13 How to check in which vc someone is?
我的机器人有这个 'wake up' 命令,它应该在 2 个特定的语音聊天之间移动 metnioned 成员,然后将它们移回原来的 vc。我设法让机器人在这 2 个 vc 之间移动,但我不知道如何检查用户在 nmoving 之前在哪个 vc 中。我尝试在线搜索并浏览文档,但我无法弄清楚。
这是我的代码:
const { Permissions,MessageEmbed } = require('discord.js')
module.exports = {
name: 'pobudka',
description: "Budzi gracza.",
execute(message, args)
{
const target = message.mentions.members.first()
const targetVC = target.voiceState.channel;
const usageEmbed = new MessageEmbed() //the embed sent if the usage is incorrect
.setColor('ff0004')
.setTitle('Poprawne użycie')
.addField('rp pobudka @user', 'zamienić @user na wzmiankę użytkownika')
if(message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) //checking if the invoking member has the administrator perms to use the command
{
if(target.voiceState === 'null')
{
message.reply('Twój cel nie jest na kanale głosowym!')
}
else
{
if(target)
{
for(let i = 5; i > 0; i--) //loop for changing the voice channels 5 times
{
target.voice.setChannel("940573437561303080") //moving the member to a different voice channel
target.voice.setChannel("946790140003631165") //moving the member to a different voice channel
}
target.voice.setChannel(targetVC)
}
else
{
message.reply({ embeds: [usageEmbed]}) //sending the usage embed
}
}
}
else
{
message.reply("Nie możesz tego użyć.") //replying if the invoking member doesnt have administrator
}
}
}
这是我遇到的错误:
C:\Users\Miki\Desktop\dc bots\jajco bot smol\commands\pobudka.js:9
const targetVC = target.voiceState.channel;
^
TypeError: Cannot read properties of undefined (reading 'channel')
at Object.execute (C:\Users\Miki\Desktop\dc bots\jajco bot smol\commands\pobudka.js:9:44)
at Client.<anonymous> (C:\Users\Miki\Desktop\dc bots\jajco bot smol\main.js:134:44)
at Client.emit (node:events:520:28)
at MessageCreateAction.handle (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\actions\MessageCreate.js:26:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
at WebSocketShard.onPacket (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\ws\lib\event-target.js:199:18)
属性 被命名为 voice
,而不是 voiceState
const targetVC = target.voice.channel
您可以使用 docs 查看某些 类
的属性
我的机器人有这个 'wake up' 命令,它应该在 2 个特定的语音聊天之间移动 metnioned 成员,然后将它们移回原来的 vc。我设法让机器人在这 2 个 vc 之间移动,但我不知道如何检查用户在 nmoving 之前在哪个 vc 中。我尝试在线搜索并浏览文档,但我无法弄清楚。 这是我的代码:
const { Permissions,MessageEmbed } = require('discord.js')
module.exports = {
name: 'pobudka',
description: "Budzi gracza.",
execute(message, args)
{
const target = message.mentions.members.first()
const targetVC = target.voiceState.channel;
const usageEmbed = new MessageEmbed() //the embed sent if the usage is incorrect
.setColor('ff0004')
.setTitle('Poprawne użycie')
.addField('rp pobudka @user', 'zamienić @user na wzmiankę użytkownika')
if(message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) //checking if the invoking member has the administrator perms to use the command
{
if(target.voiceState === 'null')
{
message.reply('Twój cel nie jest na kanale głosowym!')
}
else
{
if(target)
{
for(let i = 5; i > 0; i--) //loop for changing the voice channels 5 times
{
target.voice.setChannel("940573437561303080") //moving the member to a different voice channel
target.voice.setChannel("946790140003631165") //moving the member to a different voice channel
}
target.voice.setChannel(targetVC)
}
else
{
message.reply({ embeds: [usageEmbed]}) //sending the usage embed
}
}
}
else
{
message.reply("Nie możesz tego użyć.") //replying if the invoking member doesnt have administrator
}
}
}
这是我遇到的错误:
C:\Users\Miki\Desktop\dc bots\jajco bot smol\commands\pobudka.js:9
const targetVC = target.voiceState.channel;
^
TypeError: Cannot read properties of undefined (reading 'channel')
at Object.execute (C:\Users\Miki\Desktop\dc bots\jajco bot smol\commands\pobudka.js:9:44)
at Client.<anonymous> (C:\Users\Miki\Desktop\dc bots\jajco bot smol\main.js:134:44)
at Client.emit (node:events:520:28)
at MessageCreateAction.handle (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\actions\MessageCreate.js:26:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
at WebSocketShard.onPacket (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\ws\lib\event-target.js:199:18)
属性 被命名为 voice
,而不是 voiceState
const targetVC = target.voice.channel
您可以使用 docs 查看某些 类
的属性