【问题标题】:How do I make my discord bot have a custom status (discord.js)如何使我的不和谐机器人具有自定义状态(discord.js)
【发布时间】:2021-04-17 22:33:20
【问题描述】:

我正在尝试找到一种通过 discord.js 更新我的机器人状态的方法

我已经在网上尝试了所有解决方案,但似乎找不到任何解决方案。 我已经查看了 StackOverflow 等。

请注意我在 discord.js V12 上运行

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    我已经在网上尝试了所有解决方案,但似乎找不到任何解决方案

    您没有查看discord.js docs 网站吗?该解决方案在该网站上有明确的文档记录并且很容易发现?当涉及到这些类型的问题时,我建议先看看那里。

    我不知道您所说的 status 是什么意思(您是在谈论空闲/离线/在线状态还是“机器人正在玩 x”状态?),但我正在演示如何处理这两种状态的简单示例和下面的活动。这些示例均直接取自 discord.js 文档。

    状态

    // Set the client user's status
    client.user.setStatus('idle')
      .then(console.log)
      .catch(console.error);
    

    活动

    // Set the client user's activity
    client.user.setActivity('an activity', { type: 'PLAYING' })
      .then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
      .catch(console.error);
    

    相关资源
    https://discord.js.org/#/docs/main/stable/class/ClientUser?scrollTo=setStatus
    https://discord.js.org/#/docs/main/stable/class/ClientUser?scrollTo=setActivity

    【讨论】:

    • 嗨 Cannicide,我已经在我的代码中实现了这个,但我得到了一个 TypeError。 TypeError:无法读取 null 的属性“setStatus”
    • 这意味着您的 client 变量未定义。也许您将变量命名为bot?查看执行new Discord.Client() 的代码行,并使用该行上的变量名称。例如,如果您的代码使用bot.on("message") 而不是client.on("message"),请在此答案的代码中将client 替换为bot,它会为您工作。
    • 嗨 Cannicide,我在 "client.on" "new = Discord.Client()" 等上有一切。
    【解决方案2】:
    client.user.setActivity(`Hello World`, {type: 'PLAYING'});
    

    client.user.setPresence({ activity: { name: `Something`, type: "LISTENING" }, status: 'dnd' });
    

    有很多方法可以做到这一点。希望这会有所帮助。

    【讨论】:

    • 嗨 Jannik,我已经在我的代码中实现了这一点。但我收到一个类型错误:TypeError: Cannot read property 'setStatus' of null
    • 嘿,确保我上面给你的代码是唯一与你的机器人状态有关的代码。您在其他地方使用setStatus,但我没有使用setStatus 实现任何东西。顺便说一句圣诞快乐^^
    猜你喜欢
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 2021-07-30
    • 2021-11-10
    • 2020-03-19
    • 2021-06-19
    • 2021-05-27
    • 1970-01-01
    相关资源
    最近更新 更多