Reputation: 37
I want to make that when my bot receives a direct message, it sends it to a channel in my guild. How do I achieve this?
I do know I have to use if (message.channel.type == "dm") {}
, but how do I take what the bot receives and send it to a specific Server in a specific Channel?
Upvotes: 1
Views: 1522
Reputation: 6806
If you just want to send the text, just send its content:
client.on("message", msg => {
if (msg.channel.type == "dm") mychannel.send(msg.content); //mychannel is your TextChannel object
});
If you want to make that you can see the author & stuff like that you could use an embed (see how to build & send one here).
If you want to make like it's almost identical to someone's message, you could use a webhook:
guild.fetchWebhooks().then(webhooks => {
let myhook = webhooks.find("placeholder");
client.on("message", msg => {
if (msg.channel.type == "dm") myhook.send(msg.content, {
username: msg.author.username,
avatarURL: msg.author.avatarURL,
});
});
});
Hope this helped, let me know if you have any other question
Upvotes: 1