npmackay
npmackay

Reputation: 33

Discord bot not reading message.content

My bot is not reading the Discord chat. I want it to read the chat and if it finds certain words it will give a certain response. This is my current message event code. This is my first JavaScript project and I have just started learning it so please rip it apart so I can learn quicker :)

At the moment I can get the bot to load into discord. I can turn it on with .node but I can not get it to read a message using message.content.

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILD_MESSAGES", "DIRECT_MESSAGES"] }); 


var name = "Poker Bot";
var usersHand
let firstCardValue  
let secondCardValue
let firstCardSuit
let secondCardSuit 


//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 Fucking Casino Down');
});
    //check discord chat to see if a user has posted.
client.on("messageCreate", message => {
   //console.log is there to test user input. If it works the message in the discord channel will appear in console
    console.log(`The user has said: ${message} `);

//look for poker hand ~~~ position ~~~~ event (ex: AA CO PF )     (PF= PreFlop)


if (message.content.toLowerCase == 'AK' || message.content.toLowerCase == 'AA' || message.content.toLowerCase == 'KK'){

    message.reply("RECOMMENDED PLAY SHOVE: ALL IN")
}

Upvotes: 2

Views: 8923

Answers (2)

Thomas Elston-King
Thomas Elston-King

Reputation: 401

.content is not a method, it's a property, you must now also enable the Message Content intent on your bot page as well as in your code.

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILD_MESSAGES", "DIRECT_MESSAGES"] }); 

client.on("messageCreate", message => {
    // || "String" like you did before would return "true" in every single instance, 
    // this is case sensitive, if you wanna make it case insensitive 
    // use `message.content.toLowerCase() == "lowercasestring"`
    if (message.content == "AK" || message.content = "AA" || message.content == "KK") {     
        message.channel.send("Recommend Play is to shove all in" + message.author);
    }
})

client.login(token);

Upvotes: 5

Christoph Blüm
Christoph Blüm

Reputation: 975

Judging by your information, you dont just want to send a response if the message contains only those strings, but may just contain then. To check for that, I would suggest to use regex#test

Still as @iiRealistic_Dev rightfully mentioned: message.content is not a function, so removing the brackets is the way to go.

client.on("messageCreate", (message) => {

  if (/AK|AA|KK/.test(message.content)) {
    message.channel.send("Recommend Play is to shove all in" + message.author);
    console.log('it got to here');
  }
});

Upvotes: 0

Related Questions