How to turn a message into a string with discord.js?

by scotty_walker , in category: Javascript , 7 days ago

How to turn a message into a string with discord.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 7 days ago

@scotty_walker 

In Discord.js, you can turn a message into a string by accessing the content property of the message object. Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('message', message => {
    if (message.content.startsWith("!convertToString")) {
        const messageString = message.content.substring(15);
        console.log(messageString);
    }
});

client.login('your-bot-token');


In this example, when a message starts with the command !convertToString, it will take the content of the message (excluding the command) and log it as a string.