如何设置机器人状态

问题描述 投票:0回答:7

所以我试图让我的机器人流媒体变得抑郁,但我尝试了多种方法,但都不起作用。
我尝试过这些方法:

client.user.setPresence({ game: { name: 'with depression' }, status: 'online' });
bot.user.setGame('with depression', 'https://www.twitch.tv/monstercat');

这些似乎都没有按照应有的方式工作。如有任何帮助,我们将不胜感激。

node.js streaming bots status discord.js
7个回答
12
投票

使用这个:

const { ActivityType } = require('discord.js')

client.user.setPresence({ 
    activities: [{ 
        name: 'with depression', 
        type: ActivityType.Streaming, 
        url: 'https://twitch.tv/monstercat' 
    }], 
    status: 'online' 
});

这些是支持的活动类型和状态类型:

// Accepted activity types
ActivityType.Playing
ActivityType.Listening
ActivityType.Watching
ActivityType.Competing
ActivityType.Streaming // Lets you use url parameter. This can be a YouTube or Twitch link.
ActivityType.Custom // Unsupported in discord.js. Will be added at some point.

// Accepted statusses
"online"
"offline"
"idle"
"dnd"


8
投票

.setGame
已停产。用途:

client.user.setActivity("Game"); 

设置正在玩的游戏状态。

作为补充,如果您使用的是早期版本的discord.js,请尝试以下操作:

client.user.setGame("Game");

在较新版本的discord.js 中,此功能已被弃用。


7
投票

启动时发出消息的简单方法:

bot.on('ready', () => {
    bot.user.setStatus('available')
    bot.user.setPresence({
        game: {
            name: 'with depression',
            type: "STREAMING",
            url: "https://www.twitch.tv/monstercat"
        }
    });
});

您也可以在启动后在其他地方声明它,以根据需要更改消息:

bot.user.setPresence({ game: { name: 'with depression', type: "streaming", url: "https://www.twitch.tv/monstercat"}}); 

5
投票

从2018年开始就一直这样,抱歉不抱歉。但询问如何执行此操作的新用户需要知道 game 不再适用于此任务。

bot.user.setStatus('available')
bot.user.setPresence({
    game: {
        name: 'with depression',
        type: "STREAMING",
        url: "https://www.twitch.tv/monstercat"
    }
}

不再起作用了。您现在需要执行此操作:

bot.user.setPresence({
    status: 'online',
    activity: {
        name: 'with depression',
        type: 'STREAMING',
        url: 'https://www.twitch.tv/monstercat'
    }
})

此处引用此内容是因为“game”不再是 setPresence 的有效属性。读 有关详细信息,请参阅PresenceData 文档


2
投票
    client.user.setStatus('dnd', 'Made by KwinkyWolf') 

并将“dnd”更改为您希望其具有的任何状态。然后下一个字段“Made by KwinkyWolf”就是您改变游戏的地方。希望这有帮助:)

状态列表':

  • 在线
  • 空闲
  • dnd
  • 隐形

不确定它们是否仍然相同,或者是否还有更多,但希望也有帮助:)


2
投票

随着discord.js新版本的到来,这里的代码应该可以完美工作

const { ActivityType } = require("discord.js");

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`);

  client.user.setActivity("over you", {
    type: ActivityType.Watching,
  });
}

1
投票

setGame
已停产。您必须使用
client.user.setActivity

不要忘记,如果您要设置流媒体状态,您必须指定 Twitch URL

示例如下:

client.user.setActivity("with depression", {
  type: "STREAMING",
  url: "https://www.twitch.tv/example-url"
});
© www.soinside.com 2019 - 2024. All rights reserved.