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

by scotty_walker , in category: Javascript , 7 months ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by darion , 7 months 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.

Related Threads:

How to turn string to date using moment.js?
How to stop a message loop in discord.js?
How to pull message data from discord.js?
How to check if a message exists in discord.js?
How to delete files from a message in discord.js?
How to edit a message with discord.js?