[英]How would I detect when a user is speaking in a voice channel discord.JS v13
我已經在網上搜索了幾個小時,但沒能找到任何新的東西。
我確實知道音頻內容現在位於不同的 package 中。
我知道我來晚了一點,已經有了答案,但這里有一些使用庫 discord.js 和 @discordjs/voice 的代碼
npm i discord.js
npm i @discordjs/voice
//requirements
const discord = require('discord.js')
const voice = require('@discordjs/voice')
const client = new discord.Client({intents: Object.values(discord.Intents.FLAGS)}) //Object.values(discord.Intents.FLAGS) is used to get every intents
//on ready
client.on('ready', () => {
//log username
console.log(client.user.username)
})
//
var connection
//when a message is sent
client.on('messageCreate', (message) => {
//split message by args
const args = message.content.split(' ')
if(args[0] == "join") {
//check if the message author is in a voice channel
if(message.guild.members.cache.get(message.author.id) == null) return
//create a new voice connection (join a voice channel)
connection = voice.joinVoiceChannel({
channelId: message.guild.members.cache.get(message.author.id).voice.channel.id, //the id of the channel to join (we're using the author voice channel)
guildId: message.guild.id, //guild id (using the guild where the message has been sent)
adapterCreator: message.guild.voiceAdapterCreator //voice adapter creator
})
connection.receiver.speaking.on('start', (userId) => {
//actions here
console.log(userId)
})
}
if(args[0] == "destroy") {
if(connection == undefined) return message.channel.send('the bot isn\'t in a voice channel')
//leave
connection.destroy()
connection = undefined
}
})
client.login("token here")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.