Markoudstaal / node-red-contrib-discord-advanced

Recieve, send, edit and delete Discord messages in node-red.
MIT License
46 stars 16 forks source link

I would like to add bulkDelete but having problems figuring out how to get the right parameters #71

Open nospam2k opened 1 year ago

nospam2k commented 1 year ago

I would like to modify the deleteMessage routine to add bulkdelete but I'm not sure how to get the right parameter. I have seen messages.channel.bulkDelete(100) as an example,

nospam2k commented 1 year ago

I figured it out. It would be nice to see this as a regular feature! I'm not familiar enough with Github to do it properly.

      const deleteMessage = async () => {
          try {
            let message = await getMessage(channel, messageId);
            let resultMessage = await message.delete();
            setSuccess(`message ${resultMessage.id} deleted`, resultMessage);
          } catch (err) {
            setError(err);
          }
        }

        const deleteBulk = async () => {
          try {
            let channelInstance = await getChannel(channel);
            let resultMessage = await channelInstance.bulkDelete(100);
            setSuccess(`100 messages deleted`, resultMessage);
          } catch (err) {
            setError(err);
          }
        }
     switch (action.toLowerCase()) {
          case 'create':
            await createMessage();
            break;
          case 'edit':
            await editMessage();
            break;
          case 'delete':
            await deleteMessage();
            break;
          case 'deletebulk':
            await deleteBulk();
            break;
          case 'reply':
            await replyMessage();
            break;
          case 'react':
            await reactToMessage();
            break;
          default:
            setError(`msg.action has an incorrect value`)
        }
javis86 commented 1 year ago

In which scenarios would you use this feature? Do you have some in mind?

nospam2k commented 1 year ago

We have a channel that we use for our church where we have announcements and requests Sun morning, Sun night and Wed that have to be deleted manually before every service. What would probably be better though is to only delete messages that aren't pinned, or maybe by date, so perhaps being able to retrieve all message id's might be a better place to start. Then they can be iterated through depending on certain criteria such as date or pin or from a particular user.

dochardi commented 1 year ago

do this always request? if yes i can add its but then withe msg. For how many you wane del.