How can I use an prefix instead of slash?

Explain it simple please, first time using discord.js
37 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
I use v14, I only want prefix commands due to it being needed for the system I'm attempting to make. So is there like an tutorial.
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
^
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
🤦‍♂️ Okay give me a second to gather some screenshots.
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
I'm able to send screenshot and you can guide me right?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
No, like correct my mistakes.
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
alright
$ JJ
$ JJ11mo ago
this still good for v14 right?
$ JJ
$ JJ11mo ago
so i can just paste this in my config file ?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
ohh alright i will come back if i have a mistake
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
const { Client, Events, GatewayIntentBits } = require('discord.js');
const config = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
});

client.on('message', message => {
if (message.content === '!ping') {
message.channel.send('Pong.');
}
});

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login(token);
const { Client, Events, GatewayIntentBits } = require('discord.js');
const config = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
});

client.on('message', message => {
if (message.content === '!ping') {
message.channel.send('Pong.');
}
});

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login(token);
this correct v14 format correct?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
its still gonna work tho right?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs11mo ago
If you aren't getting content, embeds or attachments of a message, make sure you have the MessageContent intent enabled in the Developer Portal and provide it to your client:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
$ JJ
$ JJ11mo ago
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});

client.on('Events.MessageCreate', m => {
if (message.content === '!ping') {
message.channel.send('Pong.');

});

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login(token);
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});

client.on('Events.MessageCreate', m => {
if (message.content === '!ping') {
message.channel.send('Pong.');

});

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login(token);
fixed
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});

client.once(Events.MessageCreate, m => {
if (message.content === '!ping') {
message.channel.send('Pong.');

});

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login(token);
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});

client.once(Events.MessageCreate, m => {
if (message.content === '!ping') {
message.channel.send('Pong.');

});

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login(token);
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
im using daki hosting how im suppose to test it?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
my laptop cant run vsc without it crashing
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
$ JJ
$ JJ11mo ago
Actually nevermind, I just seen a way to do it with slash. But yk how circle uses prefix? I want to use prefix aswell because I'm making a bot like that. Okay, I will just use slash. I will see how it works.
TRKako
TRKako11mo ago
Maybe im a bit too late for answer this and may be useless due I use this in Discord.js v13 but this probably can help you
client.on('messageCreate', async message => {
const prefix = "!"; //You can replace the ! with your prefix
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(message.content.toLowerCase().startsWith(prefix))
{
if(command === "Command_name_01" || command === "Command_alias_02" || command === "Command_alias_03"/*etc...*/){

//Command code here

}
}
});
client.on('messageCreate', async message => {
const prefix = "!"; //You can replace the ! with your prefix
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(message.content.toLowerCase().startsWith(prefix))
{
if(command === "Command_name_01" || command === "Command_alias_02" || command === "Command_alias_03"/*etc...*/){

//Command code here

}
}
});
So, your command with prefix in a text channel should be something like this:
user input: !Command_name_01
bot output: some command
user input: !Command_alias_02
bot output: same command
user input: !Command_alias_03
bot output: same command as the first two