首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使我的不和谐机器人状态每10秒改变一次?

如何使我的不和谐机器人状态每10秒改变一次?
EN

Stack Overflow用户
提问于 2021-03-12 20:17:27
回答 2查看 1K关注 0票数 0

我希望我的机器人状态每10秒改变一次。这是我的不和谐机器人状态代码。

代码语言:javascript
复制
client.on('ready', () => {
  console.log(`Logged in as Reddit Bot`);
  client.user.setPresence({ activity: { name: 'r.help!'}, status: 'dnd' })
  .then(console.log)
  .catch(console.error);
});

我希望其他名字也可以定制。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-12 21:18:52

首先,您需要创建一个活动列表。我叫它Activities_List。注意:你可以把它叫做任何你喜欢的东西。你也可以添加你想要的多少。

代码语言:javascript
复制
const activities_list = [
    "Activitie One", 
    "Activitie Two", 
    "Activitie Three", 
    ];

然后,我们会创建一个定时器来改变活动60秒。这还将选择我们在“活动”列表中设置的活动之一并显示它。

代码语言:javascript
复制
client.on('ready', () => {
    setInterval(() => {
        const index = Math.floor(Math.random() * (activities_list.length - 1) + 1);
        client.user.setActivity(activities_list[index], {type: 'WATCHING'});
    }, 60000);
});

你总是可以把60000换到10000,也就是10秒。

票数 0
EN

Stack Overflow用户

发布于 2021-03-12 20:57:28

在你问这些问题之前,在网上看看你是否能找到你的答案。代码

代码语言:javascript
复制
    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.
    
    bot.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).
            bot.user.setActivity(activities_list[index]); // sets bot's activities to one of the phrases in the arraylist.
        }, 10000); // Runs this every 10 seconds.
    });

Source How do I make my Discord bot change status every 10 seconds?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66606670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档