С войс-чатом можно примерно так же, событие
voiceStateUpdate
const {Client, Intents} = require("discord.js");
const config = require('./config.json')
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] });
client.login(config.token);
const arr = [];
const afkRoleId = "967509853557891152"
const noAfkRoleId = "967509879642275851"
client.on("messageCreate", async (message) => {
const arrMember = arr.filter((member) => member.id === message.member.id);
if (arrMember.length > 0) {
delete arr.filter((member) => member.id === message.member.id)
}
await message.member.roles.remove(afkRoleId)
await message.member.roles.add(noAfkRoleId)
arr.push({id: message.member.id})
const sec = 3; // Запуск через 3 секунды
setTimeout(() => {
const member = arr.filter((member) => member.id === message.member.id)
if (member.length > 0) {
message.member.roles.add(afkRoleId)
message.member.roles.remove(noAfkRoleId)
}
}, sec * 1000)
})