【问题标题】:How to make my discord bot status change every 10 seconds? [duplicate]如何让我的不和谐机器人状态每 10 秒更改一次? [复制]
【发布时间】:2021-06-10 20:53:45
【问题描述】:

我希望我的机器人状态每 10 秒更改一次。这是我的 Discord 机器人状态码。

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);
});

我希望其他名称也可以自定义。

【问题讨论】:

标签: discord discord.js


【解决方案1】:

首先你需要创建一个活动列表。我将其称为Activities_List。请注意,您可以随意称呼它。您也可以根据需要添加任意数量。

const activities_list = [
    "Activitie One", 
    "Activitie Two", 
    "Activitie Three", 
    ];

然后我们将创建每 60 秒更改一次活动的计时器。这还将选择我们在活动列表中设置的活动之一并显示它。

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 秒。

【讨论】:

    【解决方案2】:

    在您提出此类问题之前,请先上网查看是否可以找到答案。 代码

        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.
        });
    

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

    【讨论】:

      猜你喜欢
      • 2018-02-26
      • 2021-01-13
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 2021-04-27
      • 2020-03-19
      • 1970-01-01
      • 2020-04-25
      相关资源
      最近更新 更多