我希望我的机器人状态每 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);
});
我希望其他名称也可以自定义。
答案 0 :(得分:0)
在提出此类问题之前,请先上网查看是否能找到答案。 代码
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?
答案 1 :(得分:0)
首先,您需要创建活动列表。我将其称为活动列表。请注意,您可以随意称呼它。您还可以根据需要添加任意数量。
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,即十秒。