discord.js v14 中的 setPresence 活动类型只能设置为“PLAYING”

6 javascript bots node.js discord discord.js

当我尝试设置机器人的状态时,我不知道类型,基本上有 4 种方式:PLAYINGWATCHINGLISTENINGSTREAMING。但我不能设置任何其他的,我只能使用默认的PLAYING

是我不专心还是在新的更新中不能像这样?

client.user.setPresence({ activities: [{ name: `discord.js v14`, type: `WATCHING` }], status: 'dnd' })
Run Code Online (Sandbox Code Playgroud)

Zso*_*ros 14

在 v14 中,您将需要使用ActivityType枚举或数字。

您可以从以下位置导入它discord.js

const { Client, GatewayIntentBits, ActivityType } = require('discord.js');
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

client.user.setPresence({
  activities: [{ name: `discord.js v14`, type: ActivityType.Watching }],
  status: 'dnd',
});
Run Code Online (Sandbox Code Playgroud)

列表ActivityType

v13 v14 v14值
"COMPETING" ActivityType.Competing 5
"CUSTOM" ActivityType.Custom 4
"LISTENING" ActivityType.Listening 2
"PLAYING" ActivityType.Playing 0
"STREAMING" ActivityType.Streaming 1
"WATCHING" ActivityType.Watching 3