简体   繁体   中英

how to save a discord chat message to a variable using message.content

I am building a discord bot where I will need to save a users message in a variable but I currently can not get message.content to come up in console.log as well as I can not get my bot to respond to if it reads a certain string in the discord channel.


var name = "Poker Bot";
var allIn = "PUSH ALL IN";
var fold = "FOLD";
var tripleBBRaise = "3 BB RERAISE"

let usersHand;


//starts the bot and sets activity to a funny quote. it also will give a command prompt notification that the bot is online
client.on("ready", () => {
    console.log(`Bot is online: ${name} !`);
    client.user.setActivity('Burning The Darn Casino Down');
});

    //check discord chat to see if a user has posted.
client.on("messageCreate", message => {

    /*test to see if the chat input works.if working the users message will be saved as a string and then written in the console*/
    console.log(`The user has said: ${message} `);

//Users input will be a poker hand. If it is one of the 3 below then tell the user the given string 
if (message.content.toLowerCase == '/AK' || message.content.toLowerCase == '/AA' || message.content.toLowerCase == '/KK'){
    message.channel.send(`RECOMMENDED PLAY: ${allIn}`) + message.author
}
   
});

I answered majority of this on your original post in a comment since I saw your edit.

If not yet done, you must enable the Message Content intent on your bot on Discord Developer Portal - Applications (then select your Application, click the "Bot" button, scroll down to Priveleged Gateway Intents then turn on "Message Content", and, probably, depending on your plan, "Server Members")

If your bot ever reaches 100 servers, assuming it's public, you'll need to verify your bot to continue using intents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM