如何使我的Discord机器人更改状态为自动

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

如何使我的Discord bot每秒更改一次状态

此代码无效

TypeError:client.user.setActivity不是函数

const activities_list = [
"with the &help command.", 
"with the developers console",
"with some code", 
"with JavaScript"
]; // creates an arraylist containing phrases you want your bot to switch through.

client.on('ready', () => {
    setInterval(() => {
        const index = Math.floor(Math.random() * (activities_list.length - 1) + 1); // generates a random number between 1 and the length of the activities array list (in this case 5).
        client.user.setActivity(activities_list[index]); // sets bot's activities to one of the phrases in the arraylist.
    }, 10000); // Runs this every 10 seconds.
});
javascript node.js nodes discord discord.js
2个回答
0
投票

尝试仅使用索引,您有一个对象而不是数组,所以它应该可以工作!希望这有效!祝你有美好的一天!


0
投票

我粘贴了您的代码,它完全按预期工作,有一件事:setInterval函数在执行之前等待,这意味着您的情况:它等待10秒,只有在这之后它才第一次设置状态,因此您可能想要稍微更改代码,以便在启动时(而不是在第一个间隔结束之后)已经设置了状态:

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.