0

im still a bit new to javascript, i started by following a tutorial i found on youtube, and that didnt seem to work, dug a bit deeper and a few more errors later, it still doesnt work. my code:

const express = require("express");
const app = express();
const prefix = require('discord-prefix');

prefix.setPrefix('b.');

app.listen(3000, () => {
  console.log("Project is running!");
})

app.get("/", (req, res) => {
  res.send("Hello World!");
})

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

client.on("messageCreate", message => {
  if (!message.content.startsWith(prefix)) return;
    
  if(message.content === "help") {
    message.channel.send("nah");
  }
})

client.login(process.env.token)

i can confirm that the token is correct, so i dont think the issue stems from there.

1 Answers1

0

Welcome to StackOverflow, AspectRx!

In your messageCreate event handler, you're returning on messages that don't start with the bot prefix. But what the statement afterward is looking for is a message that contains just the word help, which doesn't start with the prefix of b.

What you are trying to detect would be b.help, so you'd do that with (this is a guess based on discord-prefix's NPM entry):

// ...

if (message.content.startsWith(prefix.getPrefix(message.guild.id) + "help")) {
    // ...
}

I've rewritten your code with that change below.

const express = require("express");
const app = express();
const prefix = require('discord-prefix');

prefix.setPrefix('b.');

app.listen(3000, () => {
  console.log("Project is running!");
})

app.get("/", (req, res) => {
  res.send("Hello World!");
})

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

client.on("messageCreate", message => {
  if (!message.content.startsWith(prefix)) return;
    
  if(message.content.startsWith(prefix.getPrefix(message.guild.id) + "help")) {
    message.channel.send("nah");
  }
})

client.login(process.env.token)

Hope this helps!

Thunder
  • 461
  • 2
  • 6