久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 操操日| 在线中文视频 | 亚洲国产一区在线 | 911精品美国片911久久久 | 91天堂 | 亚洲精品久久久久久一区二区 | 久久一二区 | 亚洲精品久久久久久国产精华液 | 久久久精品一区 | 国产精品久久久久久久久久三级 | 天堂色| 日韩在线免费视频 | 国产一级视屏 | 欧美性猛交一区二区三区精品 | 一区二区三区亚洲精品国 | www精品 | 三级视频国产 | 午夜视频免费在线 | 日一区二区| 在线天堂免费中文字幕视频 | 亚洲视频一区二区三区 | 成人在线电影网站 | 夜夜操av | 中文字幕av免费 | 国产91在线播放精品91 | 精品日韩一区 | 古装人性做爰av网站 | 视频在线一区二区 | 成人精品免费视频 | 欧美国产日韩一区二区三区 | 国产精品久久久久久久久久久久久 | 国产盗摄视频 | 91视频在线网站 | 羞羞在线观看视频 | 日韩久草 | 日韩在线h| 亚洲精品视频在线 | 国产一二三区精品视频 | 一区二区三区高清 | caoporn国产精品免费公开 | 一区二区三区免费看 |