Javascript Discord.js setGame() 不再工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45907987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Discord.js setGame() not working anymore
提问by PMCJohn
I have been coding my Discord bot using Discord.JS for about 2 months now and I've just recently noticed that my bot isn't saying that it's playing what I'm telling it. When I first coded the bot up until recently it worked just fine. Now the 3 discord bots I have aren't showing their games.
我已经使用 Discord.JS 编写我的 Discord 机器人大约 2 个月了,我最近才注意到我的机器人并没有说它正在播放我告诉它的内容。直到最近,当我第一次对机器人进行编码时,它运行良好。现在我拥有的 3 个不和谐机器人没有展示他们的游戏。
This is the code I'm using:
这是我正在使用的代码:
const Discord = require("discord.js");
const bot = new Discord.Client();
bot.on("ready", () => {
console.log("Ready");
bot.user.setGame("Type !help");
}
回答by NintendoZaedus
.setGame()is deprecated now but you could use .setPresence()or you could use the .setActivity()which is the same thing and format as the .setGame().
Ex.
.setGame()现在已弃用,但您可以使用.setPresence()或者您可以使用.setActivity()与.setGame(). 前任。
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.user.setActivity('YouTube', { type: 'WATCHING' });
Hereis a link to the documentation in case you wanted to change 'Watching'to something else like 'Playing'.
这是文档的链接,以防您想更改'Watching'为其他内容,例如'Playing'.
回答by Pruina Tempestatis
setGame()is now deprecated, and discord.js asks you to use setActivity().
setGame()现在已弃用,并且 discord.js 要求您使用setActivity().
const Discord = require("discord.js");
const bot = new Discord.Client();
bot.on("ready", () => {
console.log("Ready");
bot.user.setActivity("Type !help");
})
Hope this helped.
希望这有帮助。
回答by LW001
The setGame() Method has stopped working, here's what you can do:
setGame() 方法已停止工作,您可以执行以下操作:
- update to latest 11.1-dev or
- use
.setPresence({ game: { name: 'nameGoesHere', type: 0 } });as a workaround instead
- 更新到最新的 11.1-dev 或
- 使用
.setPresence({ game: { name: 'nameGoesHere', type: 0 } });作为一种变通方法,而不是
Source: https://github.com/hydrabolt/discord.js/issues/1807#issuecomment-323578919
来源:https: //github.com/hydrabolt/discord.js/issues/1807#issuecomment-323578919
回答by koubi
Here's a short example of using the .setPresence that LW001 linked to:
这是使用 LW001 链接到的 .setPresence 的简短示例:
var Discord = require('discord.js');
var bot = new Discord.Client();
bot.on('ready', () => {
bot.user.setStatus('available') // Can be 'available', 'idle', 'dnd', or 'invisible'
bot.user.setPresence({
game: {
name: 'Type !help',
type: 0
}
});
});
https://discord.js.org/#/docs/main/stable/class/ClientUser?scrollTo=setGame
https://discord.js.org/#/docs/main/stable/class/ClientUser?scrollTo=setGame

