mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
Allow to set the new game types via ClientUser#setPresence and ClientUser#setGame (#1782)
* Allow to set the new game types via ClientUser#setPresence and setGame * Accept string version of types, fix options parameter, remove Presence#streaming * One line if statement, don't reuse data.game when game is already reassigned and fix error message * Removed redundant if statement
This commit is contained in:
@@ -187,6 +187,7 @@ class ClientUser extends User {
|
||||
* @property {boolean} [afk] Whether the user is AFK
|
||||
* @property {Object} [game] Game the user is playing
|
||||
* @property {string} [game.name] Name of the game
|
||||
* @property {GameType|number} [game.type] Type of the game
|
||||
* @property {string} [game.url] Twitch stream URL
|
||||
*/
|
||||
|
||||
@@ -211,7 +212,7 @@ class ClientUser extends User {
|
||||
}
|
||||
|
||||
if (data.status) {
|
||||
if (typeof data.status !== 'string') throw new TypeError('STATUS_TYPE');
|
||||
if (typeof data.status !== 'string') throw new TypeError('INVALID_TYPE', 'status', 'string');
|
||||
if (this.bot) {
|
||||
status = data.status;
|
||||
} else {
|
||||
@@ -222,7 +223,12 @@ class ClientUser extends User {
|
||||
|
||||
if (data.game) {
|
||||
game = data.game;
|
||||
if (game.url) game.type = 1;
|
||||
if (typeof game.type === 'string') {
|
||||
game.type = Constants.GameTypes.indexOf(game.type);
|
||||
if (game.type === -1) throw new TypeError('INVALID_TYPE', 'type', 'GameType');
|
||||
} else if (typeof game.type !== 'number') {
|
||||
game.type = game.url ? 1 : 0;
|
||||
}
|
||||
} else if (typeof data.game !== 'undefined') {
|
||||
game = null;
|
||||
}
|
||||
@@ -266,15 +272,18 @@ class ClientUser extends User {
|
||||
/**
|
||||
* Sets the game the client user is playing.
|
||||
* @param {?string} game Game being played
|
||||
* @param {string} [streamingURL] Twitch stream URL
|
||||
* @param {Object} [options] Options for setting the game
|
||||
* @param {string} [options.url] Twitch stream URL
|
||||
* @param {GameType|number} [options.type] Type of the game
|
||||
* @returns {Promise<ClientUser>}
|
||||
*/
|
||||
setGame(game, streamingURL) {
|
||||
setGame(game, { url, type } = {}) {
|
||||
if (!game) return this.setPresence({ game: null });
|
||||
return this.setPresence({
|
||||
game: {
|
||||
name: game,
|
||||
url: streamingURL,
|
||||
type,
|
||||
url,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user