简体   繁体   中英

How can you close an open message collector with discord.js

I am making a discord bot and I want to end an open message collector

Here is the code I have

const collector = new discord.MessageCollector(message.channel, m => m.author.id === message.author.id)
collector.on('collect', msg => {
    // here is where I want it to close
    msg.reply("You win!")
})

To stop a message collector from collecting messages simply use MessageCollector.stop()

Your code will look something like this :

const collector = new discord.MessageCollector(message.channel, m => m.author.id === message.author.id)
collector.on('collect', msg => {
  collector.stop()
  msg.reply("You win!")
})

This is something really simple to find, I just googled it and found it easily

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM