我正在尝试创建一个机器人,每当有人开始新的流时它都会通知我。
const streamChannelId = 'MY-channel-id';
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildPresences] });
client.on("ready", () => {
console.log('Bot is ready');
});
client.on("presenceUpdate", (oldPresence, newPresence) => {
console.log('oldPresence:', oldPresence);
console.log('newPresence:', newPresence);
if (!newPresence.activities) return;
newPresence.activities.forEach(activity => {
if (activity.type === "STREAMING") {
const streamChannel = newPresence.guild.channels.cache.get(streamChannelId);
if (streamChannel) {
streamChannel.send(`${newPresence.user.tag} started a stream at ${activity.url}.`);
} else {
console.log('Stream channel not found.');
}
}
});
});
client.login('my-key')
这仅当我开始活动时才有效,当我开始流时这不起作用。 根据我所做的研究,它应该在用户流式传输时也能工作,但它不起作用。 不用说我的机器人拥有所有权限。
预先感谢您的任何帮助!
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
**GatewayIntentBits.GuildVoiceStates**
]
});
也应该使用。
client.on("voiceStateUpdate", (oldPresence, newPresence) => {
if (!newPresence.member.user.bot && newPresence.streaming) {
console.log(`${newPresence.member.user.tag} started streaming!`);
}
});