我怎样才能让命令不断运行?
How can I have a command constantly run?
我正在使用 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')
}})
在聊天中发送“grimm!record”后,我希望在服务器中发送的每条消息都记录到命令提示符中,但它似乎不起作用,我也想知道如果有一种方法可以让我发送“grimm!record-stop”,那么所有消息都将停止发送到命令提示符
您可以使用 discord.js 收集器
中调用的内容来执行此操作
这里有一个full guide如果你想查看
但无论如何,你要做的就是像
一样启动收集器
// `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
}
});
我正在使用 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')
}})
在聊天中发送“grimm!record”后,我希望在服务器中发送的每条消息都记录到命令提示符中,但它似乎不起作用,我也想知道如果有一种方法可以让我发送“grimm!record-stop”,那么所有消息都将停止发送到命令提示符
您可以使用 discord.js 收集器
中调用的内容来执行此操作这里有一个full guide如果你想查看
但无论如何,你要做的就是像
一样启动收集器// `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
}
});