我的 Discord 机器人不显示活动状态我已经尝试了多种方法,但没有一个有效,我当前的代码如下所示。
client.once('ready', () => {
try {
client.user.setActivity('Test', { type: 'PLAYING' });
console.log(`Bot's Status: successfully updated`);
} catch (error) {
console.error(`Bot's Status: error while updating status`, error);
}
});
我使用的是node.js v18.18.1 和discord.js 最新版本
我已经尝试过
.setPresence
见下文,但它也不起作用。
client.once('ready', async () => {
try {
client.user.setPresence({
status: 'online',
activity: {
name: 'Test',
type: 'PLAYING'
}
});
console.log(`Bot's Status: successfully updated`)
} catch (error) {
console.error(`Bot's Status: error while updating status`)
}
});
所以要么是我不够清醒,要么就是不起作用,机器人已经获得了管理员权限,已经被踢出并重新加载,令牌已经重置,但它仍然不起作用。
如果您使用的是最新版本的
discord.js
,那么您展示的示例不再有效(它们以前可以工作,就像后面的2个主要版本一样)。
现在,要更改状态,您应该:
import { ActivityType } from 'discord.js'; // Top of the file
client.user.setPresence(
activities: [{ name: 'Test', type: ActivityType.Playing }],
status: 'online'
);
有关更多信息,请查看 setPresence() 方法的文档。
discord.js v14 中不再提供“type: 'PLAYING'”,您需要使用数字值或 ActivityType Enums
const {ActivityType} = require("discord.js");
await client.user.setPresence({
activities: [{ name: `Test`, type: ActivityType.Playing}],
status: "online",
});