Skip to content

Commit

Permalink
fixed command checker and bot not responding to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Frannerz committed Dec 5, 2023
1 parent f115383 commit 8f5124d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function chat(message) {
return openaiResponse(message);
}

chat("why is the sky blue?")
//chat("why is the sky blue?")


module.exports = { commandsList, commandLog };
Expand Down
31 changes: 7 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ client.once("ready", (c) => {
});

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

//console.log(`Received message: ${message.content}`);
if (message.author.bot || !message.content.startsWith(prefix)) {
return;
}
//console.log(`Processing message: ${message.content}`);


if (message.mentions.has(client.user.id)) {
const mentionInfo = {
Expand All @@ -42,27 +35,23 @@ if (message.author.bot || !message.content.startsWith(prefix)) {
};

mentionsLog.push(mentionInfo);

//console.log(`Bot mentioned in message: ${message.content}`);
//console.log(mentionsLog);
}

// check if the bot has been mentioned and set botMentioned variable to true or false
const botMentioned = message.mentions.has(client.user.id)|| message.channel.type === 'DM';
console.log(`Bot mentioned: ${botMentioned}`);
//console.log(`Bot mentioned: ${botMentioned}`);

if (
message.author.bot ||
(!message.content.startsWith(prefix) && !botMentioned)
) {
//console.log("message ignored!");
return;
}

//check context of message
if(botMentioned) {
if(message.content.includes('?')) {
message.reply("That's a good question! Let me think about it...");
if(message.content.includes('?') && !message.content.includes('!chat')) {
message.reply("That's a good question! Try starting your question with !chat");
}
const greeting = ["hi", "hello", "hey"];
for(const greet of greeting){
Expand All @@ -72,18 +61,12 @@ if (message.author.bot || !message.content.startsWith(prefix)) {
}
};


// Remove the prefix or mention from the message content
const command = botMentioned
? message.content.split(' ')[0].slice(client.user.id.length + 4).trim()
: message.content.split(' ')[0].slice(prefix.length).trim();
// ? message.content.slice(client.user.id.length + 4).trim()
// : message.content.slice(prefix.length).trim();



//console.log(`command passed: ${command}`);

? message.content.split(' ')[1].slice(prefix.length).trim()
: message.content.split(' ')[0].slice(prefix.length).trim();

if (command in commandsList) {
commandLog.push(message.content);
commandsList[command](message);
Expand Down

0 comments on commit 8f5124d

Please sign in to comment.