XenPanda
XenPanda

Reputation: 137

Discord Bot send message from udp connection to specific channel

I have a node.js discord bot running on my server. The bot runs a simple udp server and receives text messages from a program running a udp client. I am able to see the message in the console, but I want my bot to post the text to a channel and I can't figure out how to get the bot to post text without it being a response to user input. Any help would be greatly appreciated.

const Discord = require('discord.js');
const bot = new Discord.Client();
const { prefix, token } = require('./config.json');

    var dgram = require('dgram');
    var server = dgram.createSocket('udp4');

    server.on('listening', function() {
      var address = server.address();
     console.log('UDP Server listening on ' + address.address + ':' + address.port);
    });

    server.on('message', function(msg, remote) {
     console.log(`${msg}`);
    });

    server.bind(PORT, HOST);
    //END UDP Server

Upvotes: 1

Views: 775

Answers (1)

Syntle
Syntle

Reputation: 5174

I am assuming you want to log all messages to a specific channel, in a specific guild, you can do so by finding the guild in the client's (server in your case) guilds collection and then finding the channel from the channels collection of that guild.

You'd need to use server.guilds.cache.get(guild_ID).channels.cache.get(channel_ID).send(msg) Make sure to replace guild_ID and channel_ID with the appropriate IDs.

Upvotes: 1

Related Questions