How to do both / commands and ! commands for 1 bot.

I want to create a both that can use both /battle and !battle, they should do the exact same thing. Here is what AI kind of gave me and also I did try to search this up I only seen things for Discord.py
client.on("messageCreate", async (message) => {
if (message.author.bot) return;

console.log(`testing: ${message.content}`);

if (message.content === "t" || message.content === "battle") {
const commandFile = client.commands.get("battle");
if (commandFile) {
await commandFile.execute(message, client);
} else {
await message.reply(`Couldn't find battle.js : ${commandFile}`);
}
}
});
client.on("messageCreate", async (message) => {
if (message.author.bot) return;

console.log(`testing: ${message.content}`);

if (message.content === "t" || message.content === "battle") {
const commandFile = client.commands.get("battle");
if (commandFile) {
await commandFile.execute(message, client);
} else {
await message.reply(`Couldn't find battle.js : ${commandFile}`);
}
}
});
^ Provided by the ChatGPT ai.
18 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
d.js docs
d.js docs10mo ago
:guide: Creating Your Bot: Creating slash commands read more
Z0G0N
Z0G0NOP10mo ago
I try not to but there isn't much to go off of I was just reading what there other user linked me trying to get to work.
monbrey
monbrey10mo ago
Its a pretty bad idea to attempt this honestly, interactions and messages are not remotely the same and the user experience will be worse to have a multi-prefix approach You'd have to be able to parse and deconstruct both into a normalised canonical model for your command functions to process
Z0G0N
Z0G0NOP10mo ago
thb I'm not sure if I have a choice I am getting paid for this bot and they asked for it to do both lol You kidding right? I ask for help and your response is that? I took the job because I can do it and I just needed some help figuring shit out. Don't fucking response if you can't help simple as that. I didn't open this for shit like that.
chewie
chewie10mo ago
This falls under rule 3, so please brush up on your js fundamentals, which you seem to be lacking as Qjuh already pointed out. In the end you can take whatever job you want to take, but it's not fair to the customer if all they get is an AI coded bot that barely works, or in this case doesn't work at all. #resources has some guides to point your learning experience in the right direction, after that I suggest you refer to our lovely Discord.JS Guide.
Z0G0N
Z0G0NOP10mo ago
I know what I'm doing, I got stuck because the bot wasn't responding so I asked ai for help because I didn't see docs on what I was looking for. Then that didn't work (typical) so I came here for some help on what was wrong. I already figured it out myself but the fact that he is responding my telling me not to take the job because I can't code is not cool in any stance even if I was new. This response is better but don't assume the bot is all ai and some janky ass bot. I wouldn't take the job if I depend on ai like bro. That's honestly disrespectful as fuck to people who are just looking for tiny bits of help here and there.
chewie
chewie10mo ago
To be fair, your message implies just that. All you say is that you want to have a bot like that and that you asked the AI for help. It doesn't state what you tried before, where your own code stopped working or which documentation you searched. I can understand that the response you got might be a bit hard to you, but if there are no signs that you actually tried anything yourself here, what should we expect. We have the rule in place so people who ask for help can actually understand the answers given to them, since we aren't just spoonfeeding code here. Nobody meant any disrespect here, it's just... very direct. But I'm glad you got your issue resolved.
wen
wen10mo ago
you're gonna need to make handler that can handle both prefix and slash cmds... you're also gonna need 2 files for 1 command... 1 for prefix 1 for slash
Z0G0N
Z0G0NOP10mo ago
So my thing is what I take as a job isn't any business of this discord. I would love to be directed to where to look or what a good YouTube video is. I don't need input on my jobs I take. I already got it fam thanks though.
wen
wen10mo ago
oh shi cool 👍
chewie
chewie10mo ago
To be fair, then don't mention the job if you dont want people to comment on it.
monbrey
monbrey10mo ago
Sorry, we dont really have any good resources to point you to on doing this because it's generally not a good practice I do stand by this advice I provided earlier though - you'd have to handle both events and normalise to a standard model in some way
Z0G0N
Z0G0NOP10mo ago
yeah I got it working.
monbrey
monbrey10mo ago
Which is tricky, because youd reply to them in entirely different ways Yeah cool Abstract out as much as you can that is common between the two, but dont force interactions and messages together. I often see people trying to shove both into a single handler and that fails pretty hard
Z0G0N
Z0G0NOP10mo ago
I just created a class and one or the other will check to see if it was already called/created I only mentioned the job because it's not my choice on what goes in the bot it was a set request by the owners. basically saying I have to get this done one way or another. It wasn't a conversation starter by any means. I came here to talk or get some direction on programming this bot. do you guys still have marked as solved?
monbrey
monbrey10mo ago
Yeah its up in the second message
Z0G0N
Z0G0NOP10mo ago
oh mb
Want results from more Discord servers?
Add your server