📅  最后修改于: 2023-12-03 15:05:11.447000             🧑  作者: Mango
setPresence
Discord.js - JavascriptThe setPresence
method in Discord.js allows a bot to set its own presence status, such as online, idle, or invisible. This method can be executed on the client's instance of bot.
client.user.setPresence(presence);
presence
- an object containing the properties to set for the bot's presence status. The following are the properties that can be set:
game
: an object that represents the game being played. It can have the following properties:name
: the name or title of the game.type
: the type of game being played. It can be one of the following:0
for playing
1
for streaming
2
for listening
3
for watching
url
: the URL for the game being played, if applicable.status
: the status of the bot. It can be one of the following:online
: the bot is online and active.idle
: the bot is online but inactive.dnd
: the bot is online but does not disturb.invisible
: the bot is offline and hidden.afk
: a boolean representing whether the bot is AFK or not.client.on('ready', () => {
client.user.setPresence({
game: { name: 'Hello World', type: 0 },
status: 'online',
afk: false
});
});
// Output:
// Bot's presence is set to: Hello World playing
In conclusion, setPresence
is a useful method for setting a bot's presence status in Discord.js. With its parameters, we can customize the bot's presence status to our liking.