简体   繁体   English

如何让命令不断运行?

[英]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.

相关问题 JavaScript:我怎样才能有一个持续运行的进程来进行监控? - JavaScript: how can I have a constantly running process for the purpose of monitoring? 我有一个不断改变身高的div。 我怎样才能得到第二个div来不断采用第一个div的高度? - I have a div that constantly changes height. How can I get a second div to constantly adopt the height that the first div is? 如何不断更新图像? - How can I constantly update an image? 如何使用Javascript将流数据(已转换为颜色的数据)不断地推送到index.html中的连续div中? - How can I push constantly streaming data (which I have converted to color) into successive divs in my index.html using Javascript? 我如何让 Dojo 复选框运行命令? - How do i have a Dojo checkbox run a command? 如何让我的FavIcon不断改变? - How can I make my FavIcon change constantly? 如何不断检查页面元素之间的冲突? - How can I constantly check collision between page elements? 如何实现需要持续运行的节点应用程序? - How can I implement my node application that needs to be constantly running? 有没有办法让我拥有一组不同的 id,允许在 discord.js 中运行命令 - is there a way i can have an array of different ids that are allowed to run a command in discord.js 如何在 lerna exec 命令中执行 npm run 测试? - How can I perform a npm run test in a lerna exec command?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM