[英]How can I have a command constantly run?
Im using Discord.js, and i would like my bot to keep a command activated until told to stop我正在使用 Discord.js,我希望我的机器人保持激活命令,直到被告知停止
client2.on('message', message => {
if (message.content === 'grimm!record') {
message.channel.send('Recording has Started in the Command Prompt')
console.log(message.content)
console.log('Grimm 2 - Recording has Started')
}})
once "grimm,record" is sent in the chat, I want every message that is sent in the server to get recorded into the command prompt, but it does not seem to be working, and I also want to know if there is a way that if i send "grimm!record-stop" then all messages will stop getting sent to the command prompt一旦在聊天中发送“grimm,record”,我希望服务器中发送的每条消息都记录到命令提示符中,但它似乎不起作用,我也想知道是否有办法如果我发送“grimm!record-stop”,那么所有消息都将停止发送到命令提示符
You can do this using what is called in discord.js Collector您可以使用 discord.js 收集器中的内容来执行此操作
Here is a full guide if you want to check it如果您想检查它,这是一个完整的指南
But anyways all you want to do is start collector like但无论如何,你想做的就是开始收集器
// `m` is a message object that will be passed through the filter function
const filter = m => true; //A filter that accepts any type of message just returns true
const collector = message.channel.createMessageCollector(filter); //starts the collector
collector.on('collect', collectedMessage=>{
console.log(collectedMessage.content); //console logging collected message as you wanted every message getting sent to be sent to console else use end event with map() function
if(collecteddMessage.content === "grimm!record-stop"){ //checking message content
collector.stop(); //ends collector
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.