如何让我的 Discord 机器人每 10 秒左右更改一次状态? (包括 "Listening to"、"Playing" 和 "Watching" 等内容)
How can I make my Discord bot change its status every 10 seconds or so? (Including things like "Listening to", "Playing" and "Watching")
请告诉我该怎么做。
这是我的代码不起作用:
let activity = ["`${client.users.size} commands | ><help`, {type: "LISTENING"}", "`on ${client.guilds.size} servers | ><help`, {type: "PLAYING"}
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);
});
我猜你对数组中的引号有疑问,试试这个:
let activityTypes = ['PLAYING','STREAMING','LISTENING','WATCHING']
let randomType = activityTypes[Math.floor((Math.random()*activityTypes.length))]
setInterval(async ()=>{
await client.user.setActivity('Your text here.', { type: randomType })
},10000)
但请记住,10 秒可能会达到不和谐 API 速率限制。
请告诉我该怎么做。 这是我的代码不起作用:
let activity = ["`${client.users.size} commands | ><help`, {type: "LISTENING"}", "`on ${client.guilds.size} servers | ><help`, {type: "PLAYING"}
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);
});
我猜你对数组中的引号有疑问,试试这个:
let activityTypes = ['PLAYING','STREAMING','LISTENING','WATCHING']
let randomType = activityTypes[Math.floor((Math.random()*activityTypes.length))]
setInterval(async ()=>{
await client.user.setActivity('Your text here.', { type: randomType })
},10000)
但请记住,10 秒可能会达到不和谐 API 速率限制。