So lemme lay out the scene: (these aren't what the code actually says but for the sake of space in the explanation, I left it short)
Person A sends this message:
@Bot slap @membername
Bot replies with
@messageauthor slapped @membername
Perfect execution and that code works just fine.
example 2
@Bot slap @membername (with any number of args following the second mention)
or
@bot slap (anything can go here doesn't matter) @membername
Bot replies with
@messageauthor no can do
Perfect execution and that code works just fine
example 3
@bot slap
Bot replies with
@bot slapped @messageauthor because they didn't specify who to slap
Perfect execution and that code works just fine
example 4 (and the one I'm having trouble with)
@Bot slap membername
with no mention
or
@Bot slap asdfg
Bot replies with
@messageauthor slapped @Bot
I have tried several dozens of different ideas to get this working so that it will respond with the "no can do" response. There are 2 possible solutions that I am after.
- get the @bot parsed out like a normal prefix (been unsuccessful as my prefix is not @, its something stupid long that no one will ever use so that all commands sent are sent with bot mentions only).
- Somehow make this (and other commands similar) to require a second mention.
- I'm open for other ideas as well.
Here is the code:
const Discord = require('discord.js')
const sarcasm = require('../assets/json/sarcasm.json'); //has variations of no can do but with major sarcasm in it
module.exports.run = async (bot, message, args) => {
let user = message.mentions.users.last();
const notargetEmbed = new Discord.MessageEmbed()
.setColor('#ff6600')
.setTitle('Slap')
.setDescription(`<@` + bot.user.id + `> slapped <@` + message.author.id + `> because they didn't specify who to slap, so it boomeranged.`)
.setImage('my_image_gif_here.gif')
.setFooter('Discord Server Name', 'icon_here.png')
if (!args.length) {
return message.channel.send(notargetEmbed);
}
if (args[1]) {
return message.channel.send(`<@${message.author.id}>, ` + sarcasm[Math.floor(Math.random() * sarcasm.length)]);
}
const slapEmbed = new Discord.MessageEmbed()
.setColor('#ff6600')
.setTitle('Slap')
.setDescription(`<@` + message.author.id + `> slapped <@` + user.id + `> across the face!`)
.setImage('my_image_gif_here.gif')
.setFooter('Discord Server Name', 'icon_here.png')
message.channel.send(slapEmbed);
};
module.exports.help = {
name: "slap"
}
args[1]
is truthy? Not sure if I'm missing something.if
condition would betrue
(args[1]
is truthy). Why would it return "@messageauthor slapped @Bot"?