Search code examples
javascriptwebsocketdiscord.jsbots

How to get message information from discord bot through websocket and webhook


So I currently am able to receive messages from a discord channel and post them with a webhook, but when I get information sent by a bot I receive @deleted-role when I'm trying to get information from one of my discord servers and post it into another.

I currently have this code to send the information retrieved from the JSON data array received from the API:

if (d.author != null) {
        if (d.channel_id === testchannel) {
            if (d.attachments) {
              let client = new WebhookClient({ url: "https://ptb.discord.com/api/webhooks/MY WEBHOOK" });
          
              if (d.content){
                let content = d.content ? d.content : { embeds: d.embeds };
                client.send(content);
              }
              for (let i = 0; i < d.attachments.length; i++) {
                let image = d.attachments[i].url;
                client.send(image);
              }
            }
            else {
                let content = d.content ? d.content : { embeds: d.embeds };
                let client = new WebhookClient({ url: "https://ptb.discord.com/api/webhooks/MY WEBHOOK" })

                client.send(content);

            }
        }

Let me know if you need anymore information on this.


Solution

  • I was able to figure out why I was getting only Deleted_Role. My embeds weren't working properly. I just spliced out deleted role from the content I received. Closing this out.