[英]can you help me for limit my command (discord.js)
i want to ask you how I can DM people with a bot for the new of my server because i have a command but its send to much DM like 20我想问你我如何用机器人为我的新服务器发送 DM 人,因为我有一个命令,但它发送给很多 DM,比如 20
script:脚本:
client.on('message', function(message) {
if(message.content === "!dm"){
if(message.deletable) message.delete();
i = 0;
message.guild.members.forEach(member => {
if(i < 1){
var interval = setInterval (function () {
member.send(` message`).catch(e => {});
}, 50)
}
})
}
});
I would reccommend using async await instead of setTimeout as you have a better control over the flow of the code.我建议使用 async await 而不是 setTimeout,因为您可以更好地控制代码流。 Try this code:
试试这个代码:
client.on('message', (message) => {
if(message.content === "!dm"){
if(message.deletable) message.delete();
let count = 0;
message.guild.members.cache.forEach(async mem => {
if(count < 5){ /*this is your users limit. Change it as per your need*/
await mem.send("the messasge").catch(console.error);
count++;
}else{
return;
}
})
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.