#DiscountedJames DiscordBot Help
1 messages · Page 1 of 1 (latest)
Oh hi
This is it
Ok so basically heres what you need
ok
rename the thread to "DiscountedJames DiscordBot Help"
or something like that bc a mod might take this down if it is "ok"
DiscountedJames DiscordBot Help
alright thats better
k Ima send you a snippet of my code
try {
client.commands.get(commands).execute(client, message, args);
} catch (e) {
message.reply(`there was an error trying to execute that command! \`${e}\``).then((e) =>{
console.log(e)
})
console.log(error)
}```
oh wait let me fix somethings for you
ok
ok so its message.reply('Test is working')
This is the error
const [cmd, ...args] = message.content
.slice(prefix.length)
.trim()
.split(/ +/g);
i did this
const command = client.commands.get(cmd.toLowerCase()) || client.commands.find(c => c.aliases?.includes(cmd.toLowerCase()));
nope
thats better
this has both command and args
all on one line?
lemi send the whole file
k
if (
message.author.bot ||
!message.guild ||
!message.content.toLowerCase().startsWith(prefix)
)
return;
if (!message.channel.permissionsFor(message.guild.me).has("SEND_MESSAGES")) return
const [cmd, ...args] = message.content
.slice(prefix.length)
.trim()
.split(/ +/g);
const command = client.commands.get(cmd.toLowerCase()) || client.commands.find(c => c.aliases?.includes(cmd.toLowerCase()));
if (!command) return;
try{
await command.run(client, message, args);
} catch(err) {
console.log(err)
}
wait are u making slash command?
no
no hes/she not
then u can use this
idk
Where do I add this bit tho
I'm using v12 because I understand it better when I'm making a new bot
v13 isnt that diff
its not
add intents
and uh some methods changed
and removed
Where am I putting this
I have this
do u have a seperate event file?
I had to dig up an old repl that still had discord.js v12
bc you can't download it anymore
and v13 doesn't work on repl
bc their node isn't up to date
they are on node version 8
This
6.14.15
yeh
perfect
it should be updated
show the ending
yea see that lonely bracket
yeah
no.
yea }
oh then uhh
try adding another })
and if that gives you an error remove the }
thats what I do
lol
show the whole file
use source bin
yeh
rip airpod
no like not a screen shot
it will be a function
arrow function
(message) => {
add the
=>
after mesage
like that
yea
we are dum
thats what I was about to say
It works but the commands responds with nothing
client.on("messageCreate", async (message) => {```
yep
try now
oh
no
or u are in main file?
hmmm
also where in here does it say to go to my test.js file
it uh
u see
the
command.run
yea its not command.run
no no
no its not
its searching for the test.cjs there
How does it know which one though the folder could have a ban.cjs there
whats cjs..?
its commando js
oh.
its only v12
thats y..
thats why
welp then im out..
same
idk much v12
good luck @wicked wave
Yes
not sure tbh
open the
ok for starters you can't just change the file name
index.js right
you have to install regular discord.js
ok so
ok that is good
it is discord.js
y were u using cjs?
probably new to it lol
ig
yea commando is v12 only
bc when I used test.js it got an error in console to change it to cjs
theres v14?
nop
alr well I'm out
the test.js file?
best of luck you you james
stay here
welp he is gone
i will try my best to help
can u
do
const prefix = "-"
on the top
import DiscordJS, { Intents } from 'discord.js'
import dotenv from 'dotenv'
dotenv.config()
const client = new DiscordJS.Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
]
})
const prefix = '-';
import fs from 'fs'
client.commands = new DiscordJS.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.cjs'));
for(const file of commandFiles){
const command = import(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', () => {
console.log('worker is Online')
client.user.setActivity({ type: "PLAYING", name: `nothing` })
const guildID = '866288311416913932'
const guild = client.guilds.cache.get(guildID)
let commands
if (guild) {
commands = guild.commands
} else {
commands = client.application?.commands
}
commands?.create({
name: 'test',
description: 'Test CMD',
})
})
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) {
return
}
const { commandName, options } = interaction
if (commandName === 'test') {
interaction.reply({
content: 'Test is working',
ephemeral: true,
})
}
})
//TEST CMD
client.on('messageCreate', (message) => {
if (message.content === 'test') {
message.reply({
content: 'Test is working',
})
}
})
//Prefix TEST CMD
client.on("messageCreate", async (message) => {
if (
message.author.bot ||
!message.guild ||
!message.content.toLowerCase().startsWith(prefix)
)
return;
if (!message.channel.permissionsFor(message.guild.me).has("SEND_MESSAGES")) return
const [cmd, ...args] = message.content
.slice(prefix.length)
.trim()
.split(/ +/g);
const command = client.commands.get(cmd.toLowerCase()) || client.commands.find(c => c.aliases?.includes(cmd.toLowerCase()));
if (!command) return;
try{
await command.run(client, message, args);
} catch(err) {
console.log(err)
}
})
client.login(process.env.TOKEN)
Thats my index.js
wait u dont have
//TEST CMD
client.on('messageCreate', (message) => {
if (message.content === 'test') {
message.reply({
content: 'Test is working',
})
}
})
this works?
yes.
huh
no
no
how do u start ur bot?
?
yeah
ok so
The console error
whts the startup command?
let me find it
its in the startup tab
if [[ -d .git ]] && [[ 0 == "1" ]]; then git pull; fi; if [[ ! -z ${NODE_PACKAGES} ]]; then /usr/local/bin/npm install ${NODE_PACKAGES}; fi; if [[ ! -z ${UNNODE_PACKAGES} ]]; then /usr/local/bin/npm uninstall ${UNNODE_PACKAGES}; fi; if [ -f /home/container/package.json ]; then /usr/local/bin/npm install; fi; /usr/local/bin/node /home/container/index.js
ima give u a github link to a template
ok
use that its very good
ok thanks
yeha
so u see the .get("740082553561808906")
so in there
u put ur guid id if u want slash commands for 1 guild
yeah ok
or do this for every guild
yeah like this
it works?
also 1 more this the commands u make will be in a subfolder not in
the commands folder
like this
module.exports = {
name: 'ping',
run: async (client, message, args) => {
message.channel.send(`${client.ws.ping}ms ping!`)
}
}
and this is how to make
commands
yeah I see