久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在給定的不和諧頻道中搜索滿足條件的所有消息

Search a given discord channel for all messages that satisfies the condition and delete(在給定的不和諧頻道中搜索滿足條件的所有消息并刪除)
本文介紹了在給定的不和諧頻道中搜索滿足條件的所有消息并刪除的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試編寫一個代碼,該代碼將檢查頻道中的所有消息以查找包含某些單詞的消息,如果確實包含這些單詞,則將其刪除.所以像:

I was trying to make a code that will check all messages in a channel for messages that contain certain words, and delete them if it does contain them. So something like:

if(msg.content.startsWith(prefix+'clean') {
  let check = msg.content.split(prefix+'clean')[1]; // Condition, in this case if it containts a certain string
  msg.channel.fetchMessages().then(msgs => { // Get messages to check
    let msglog = msgs.array() // Make an array with all the messages fetched
    for(var i = 0; i < msglog.size; i++) { // Loop to check all messages in array
      if (check in msglog[i]) {
        // Code to delete that message
      };
    };
  });
};

我知道這不會檢查整個頻道,它只會檢查最后 50 條消息,但我不知道如何讓它檢查整個頻道,所以在我找到方法之前會這樣做.

I am aware that this will not check the entire channel and it will only check the last 50 messages, but I do not know how to make it check the whole channel so this will do until I find out how to do that.

但是什么代碼會刪除通過檢查的消息?或者我可以用什么不同的方法來解決這個問題?

But what code would delete the message that passes the check? Or any different way I could approach this?

我好像還不夠清楚,假設一個頻道有以下對話:

It seems I was not clear enough, so let's say a channel has the following conversation:

A:伙計們!

B 人:嗨

C 人:再見

假設我想通過我的機器人刪除所有帶有Hi"的消息,我應該怎么做?注意:我不會在消息發送后立即刪除它,我只想在我想刪除它時刪除它.

Let's say I want to delete all the messages with "Hi" in it through my bot, how should I do this? Note: I do not with to delete a message right after it has been sent, I only want to delete it when I want to do so.

推薦答案

bulkDelete 功能刪除給定的新消息超過兩周.

The bulkDelete function delete given messages that are newer than two weeks.

if(msg.content.startsWith(prefix+'clean') {
  let check = msg.content.split(prefix+'clean')[1]; // Condition, in this case if it containts a certain string
  msg.channel.fetchMessages().then(msgs => { // Get messages to check
    let msgDel = msgs.filter(msgss => msgss.content.includes(check)) // Finds all messages with 'check'
    msg.channel.bulkDelete(msgDel) // Deletes all messages that got found
  });
};

要刪除超過 2 周的消息,您必須手動遍歷消息以刪除它們:

To delete the messages older than 2 weeks, you have to iterate through the messages manually to delete them:

async function deleteReturnLast(chan, option, prevMsg, cond) {
  return chan.fetchMessages(option)
    .then(async msgs => {
      if (msgs.size === 0){
    if (cond(prevMsg)) {
      prevMsg.delete()
        .then(d => console.log('last message deleted: ' + d.content))
        .catch(err => console.log('ERR>>', err, prevMsg.content, option.before));   }
    return prevMsg;
      };
      let last = msgs.last();
      for (const[id, msg] of msgs) {
    let tmp = (id === last.id) ? prevMsg : msg;
    if (cond(tmp)) {
      tmp.delete()
        .then(d => console.log('Message deleted: ' + d.content))
        .catch(err => console.log('ERR>>', err));
    }
      };
      return last;
    })
    .catch(err => console.log('ERR>>', err));
}

function cond(msg) {
  return !msg.content.includes('a');
}

client.on('message', async function(msg) {
  let chan = msg.channel;
  let last = chan.lastMessage;
  while (last !== (last = await deleteReturnLast(chan, {limit: 2, before: last.id}, last, cond))){
  };
});

這篇關于在給定的不和諧頻道中搜索滿足條件的所有消息并刪除的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 国产999精品久久久久久绿帽 | 黄色网址免费在线观看 | 免费中文字幕日韩欧美 | 午夜电影网 | 伊人一区 | 日韩精品免费 | 一本一道久久a久久精品蜜桃 | 久久精品 | 欧美最猛黑人 | 中文字幕日韩三级 | 91精品国产一区二区三区蜜臀 | 国产成人福利在线观看 | 九色av| 欧美视频第二页 | 完全免费在线视频 | 欧美久久一区二区三区 | 97超碰人人| 91免费小视频 | 99久久精品国产麻豆演员表 | 97日韩精品 | 亚洲欧美在线观看视频 | 麻豆视频国产在线观看 | 国产自产21区 | 成人福利 | 欧美日一区二区 | 欧美色图综合网 | 亚洲 自拍 另类 欧美 丝袜 | 中文字幕视频在线免费 | 精品少妇一区二区三区日产乱码 | 国产成人免费视频 | 成人免费视频观看视频 | 国产精品美女久久久久久久网站 | 99精品国产一区二区三区 | 亚洲国产一区二区在线 | 久久综合爱 | 天天看片天天干 | 自拍偷拍3p| 在线观看精品视频网站 | 老司机67194精品线观看 | 国产精品久久国产精品 | 精品国产18久久久久久二百 |