Code Issues Resulting in Nothing Happening and 'send' Undefined - javascript

Here is the error I'm receiving in the console regarding 'send' undefined: https://pastebin.com/CRmZwUA4. This happens when testing our profanity filter. The word on the list is deleted and removed and the bot replies with a message stating that it was removed. This is working as it should except for the error in the console.
For the extra code not working, I'm not sure if it has to do with the error above. A few days ago the code worked fine until I made adjustments to a different section of code which was just to add in a check for the profanity filter to see if a filtered word was said by a member with a specific role. If they had the role, the filter was then ignored so they weren't blocked out. It would seem the 2 would have to do with each others but I can't figure out what the check would even affect. Again the filter worked as intended where the check was fine but the other fun code stopped working.
The code pasted below shows the fun code that stopped working. When a user besides the person being tagged says "bum" the bot replies with a fun message. That's what it's supposed to do. When any user says "bum" now, nothing happens. The concern that I have is that the testing bot used in a different server with the same code works with this perfectly fine. But the real bot on our main server is not working with the code. I even copied the file to the main bot again and restarted the bot and still nothing is happening. Sorry for the long winded post, I just want to make sure i've explained everything clearly.
if (words.includes('bum')) {
if (message.author == '<#458068171241553921>') return;
else {
setTimeout(function() {
message.channel.send('Are we talking about <#458068171241553921>?!');
}, 1500);
}
}
for (let x = 0; x < profanities.length; x++) {
if (message.member.roles.some(role => role.id === '613427562550394891')) return;
else {
if (message.content.toUpperCase().includes(profanities[x].toUpperCase())) {
message.channel.send('Oooooooh you said a bad word!');
client.channels.get('484375912389935126').send(`Message was deleted due to use of a blocked word:\n\n"${message.content}"`);
message.delete();
return;
}
}
}

I figured out the issue. It was the new check that I had added. The check was to see if people had the role then it wouldn't respond. I had the check outside of the For loop which is what messed everything up. I placed the If statement inside the for loop instead so the new code is below
for (let x = 0; x < profanities.length; x++) {
if (message.member.roles.some(role => role.id === '483641589193900043')) return; {
if (message.content.toUpperCase().includes(profanities[x].toUpperCase())) {
message.channel.send('Oooooooh you said a bad word!');
client.channels.get('484375912389935126').send(`Message was deleted due to use of a blocked word:\n\n"${message.content}"`);
message.delete();
return;
}
}
}

Related

i keep getting an error about .position in discord.js

So i tried making a kick command in dicors.js(creating a bot). I did a little bit of research and I ended up with copying a code from stack overflow. The code was working fine but i wanned to make it so if "x" that has a lower rank tries to kick "y" which has higher rank, the bot would then send a message to "x" that he can't kick a higher rank person. (both x and y are users)
The code that i copied also has this function included and i keep getting this error
let authorHighestRole = msg.member.highestRole.position;
^
TypeError: Cannot read property 'position' of undefined
I searched online: nothing.
I tried some stupid things like adding () to .position
I searched in the Discord.js docs and still nothing.
I came to the conclusion that the code is old.
Here is my code
case 'kick' :
if(msg.channel.type === 'DM') {
msg.channel.send('This command can use only in guide');
return;
};
if(!msg.member.hasPermission('KICK_MEMBERS')) {
msg.channel.send('You have no permissions to do that');
return;
};
let mentionMember = msg.mentions.members.first();
if(!mentionMember) {
msg.channel.send('Please specify the person you want to kick!');
return;
}
if(!mentionMember.kickable) {
msg.channel.send('I can\'t kick this user!');
return
};
//Get the highest role of user for compare
let authorHighestRole = msg.member.highestRole.position;
let mentionHighestRole = mentionMember.highestRole.position;
//If mention user have same or higher role, so show this error msg
if(mentionHighestRole >= authorHighestRole) {
msg.channel.send('You can`t kick members with equal or higher position');
return;
};
mentionMember.kick()
msg.channel.send(`${mentionMember.displayName} was kicked`)
break;
Any help would be appreciated.
member doesn't contain a property called highestRole, I believe the property you're looking for is: member.roles.heighest.
see docs: https://discord.js.org/#/docs/main/stable/class/GuildMemberRoleManager?scrollTo=highest
msg.member.roles.highest.position

Words filter stopped working - Discord.JS 12

Hello!
So I'm currently updating my bot to version 12.3.1 of DiscordJS. Unfortunately, I got stuck on a problem that I can't really find a workaround. So, my bot has a module to filter out all of the bad words, like profanity, racial slurs, etc.
It's currently working just fine on 11.4, but cannot get it to work on 12.3.1
For some reason, the bot just does not react at all to given message.
I had two "filters" one for words, one for invites. Both of them stopped working.
bot.on('message', async message => {
// Events Listeners
if (message.author.bot) return;
if (message.channel.type === 'dm') return;
let messageArray = message.content.split(' ');
let command = messageArray[0];
let args = messageArray.slice(1);
if (!command.startsWith(prefix)) return;
let cmd = bot.commands.get(command.slice(prefix.length)) || bot.aliases.get(command.slice(prefix.length));
if (cmd) cmd.run(bot, message, args);
// First filter
var array = ['testing', 'yes', 'no'];
if (array.includes(message.content.toLocaleLowerCase())) {
message.channel.send('test')
}
// Second filter
if (message.content.includes('discord.gg/') {
message.delete()
}
}
That's the current one I found from another StackOverflow post, made 2 months ago.
Discord.js V12 Rude words filter not working
I'd really love to get some help if possible, as I can't find any reason why this feature has stopped working.
Thank you! :)
Your filters are after your command handling logic.
You have the line:
if (!command.startsWith(prefix)) return;
early in your code, and this causes message handling to terminate immediately on any message which is not a command. Due to this, the code will never reach your filters unless the message starts with your bot's prefix, at which point the message content cannot possibly be equal to any of the words and is extremely unlikely to contain discord.gg/.
Simply move your filters to the beginning of your message handler. Or alternatively separate the command handling and filter handling into separate functions, so that the return statement above only exits the command handling and the filter handling will still run.

JavaScript Coding Challenge help - Quiz Question Do While Loop

I'm doing a coding challenge that requests we ask just one multiple choice question - if the answer is correct, it prints a congrats and exits the program. if wrong, it offers the user the chance to try again or exit the program. I've only been coding for a few weeks and it still simpler for me to use if/else if for this - but we need to use a Do While loop. Below is what i have so far and any advice would be appreciated:
let answer = [""]
do {
prompt("What shape is the Earth? \nA: Square\nB: Triangle\nC: Round\nD: Flat");
} while (answer != C);
console.log("I'm sorry you're an idiot.")
let retry = alert("Try again? Y/N")
if (retry == Y) {
//how to reset loop from here?
}
else if (retry == N) {
//how to exit program?
}
if(answer === C) {
console.log("Congratulations! You're not an idiot :)")
}
Let's put your code in a snippet:
let answer = [""]
do {
prompt("What shape is the Earth? \nA: Square\nB: Triangle\nC: Round\nD: Flat");
} while (answer != C);
console.log("I'm sorry you're an idiot.")
let retry = alert("Try again? Y/N")
if (retry == Y) {
//how to reset loop from here?
}
else if (retry == N) {
//how to exit program?
}
if(answer === C) {
console.log("Congratulations! You're not an idiot :)")
}
Now click the Run code snippet button above and watch what happens.
Do you see the error message? That is the first thing to fix, and this is your first step in learning how to debug your code.
Debugging is one of the most valuable skills you will need in programming. For JavaScript in a browser, you will want to get familiar with the Developer Tools that are built into every browser. If you use Chrome or the new Edge browser, here is a guide to the Chrome DevTools.
The DevTools include an interactive Console where you can see error messages and type in expressions to see what they do. They also include a Source view where you can set breakpoints in your source code and look at your variables, and many other debugging features.
A Stack Overflow snippet like the one above has a built-in Console so you can see the error message right here in the page. For code you're running in your own web page, use the browser's developer tools to see errors, test expressions, set breakpoints, and view your variables.

Overlapping commands?

I'm trying to make a fun little discord chat bot with JavaScript and node.js and I'd like to put in a specific command without it affecting another one I already have set up.
She works wonderfully on all the servers I have her on, and I've got it set up so that when someone in the server says anything with "rei are", she responds with a constant from areResponses.
//const!!!
const areResponses = ["HELL yeah!", "Yep!", "I'm pretty sure that's true!", "I\'m not gonna put all the responses here because then it'd be too long..."];
//theres some other bot stuff (console log, now playing) under here but it isn't relevant until...
//the basics...
if (message.content.toLowerCase().includes("rei are")) {
var response = areResponses [Math.floor(Math.random()*areResponses.length)];
message.channel.send(response).then().catch(console.error);
}
What I want to have happen is, preferably, this command to function without setting off the "rei are" command I coded in.
if(message.content.toLowerCase().includes("rei are you happy")) {
message.channel.send("Yes, absolutely.");
}
As of right now, whenever I try to input the above command, it just triggers the "rei are" command AND the "rei are you happy" command with two messages...
else/if chains work beautifully for this actually!!!
if(message.content.toLowerCase().includes("rei do you like girls")) {
message.channel.send("Yes, absolutely. Girls are just... yeah...");
}
else if (message.content.toLowerCase().includes("rei are")) {
var response = areResponses [Math.floor(Math.random()*areResponses.length)];
message.channel.send(response).then().catch(console.error);
}
All you need to do is put the command that would overlap with the larger commands at the very bottom of the else if chain, and then you're good!!

Facebook appMobi debugging when theres no distinct error

I am working on a project in appMobi, and this project has recently reached it portion that is related to facebook. However there just seems to be soo many moving parts that its virtually impossible to tell whats going on with what where and how.. more so, when everything works in the emulator but not on a device, where there is no console, no error log, nothing to work with to try and figure out the issue.
The image below is the only error I get on my device. When attempting to communicate with facebook, through appMobi specific methods. I have litteraly copied and pasted there code trying to make this work cause I know once I can see this working and how its going to work I can then start building logic around something I actually want to do. That being a mute point at the moment. Anyway, when I run this same exact code in the emulator it works exactly as expected. But running it in Test Anywhere on the device itself seems to be where this conflict is coming in.
Soo I am wondering, has anyone had this issue before out there on stack? If so what did you do to fix it? Whats the work around? Whats the means of how you debugged it and came to the conclusion as I am sure I am going to run into similar problems down the road and debugging on the device is also a bonus.
my javascript currently:
document.addEventListener("appMobi.facebook.login",function(e){
if (e.success == true)
{ console.log("Facebook Log in Successful"); }
else
{ console.log("Unsuccessful Login"); }
},false);
function fbLoginCheckz()
{
try{
AppMobi.facebook.login('user_birthday,user_about_me,user_status,offline_access,publish_stream,publish_actions,email,read_friendlists,publish_checkins,create_event');
}catch(e){
alert("Error Caught [FB 1]: "+e.message);
}
}
document.addEventListener("appMobi.facebook.logout",function(e){
if (e.success == true)
{ console.log("Logged out of Facebook"); }
else
{ console.log("Unsuccessful Logout"); }
},false);
var facebookUserID = "me"; //me = the user currently logged into Facebook
document.addEventListener("appMobi.facebook.request.response",function(e) {
console.log("Facebook User Friends Data Returned");
if (e.success == true) {
var data = e.data.data;
var outHTML = "";
for (var r=0; r< data.length; r++) {
outHTML += "<img src='http://graph.facebook.com/" + data[r]["id"]
+ "/picture' info='" + data[r]["name"] + "' />";
}
$("#blah").empty().html(outHTML);
document.removeEventListener("appMobi.facebook.request.response");
}
},false);
my html:
<br><br>
<div id="blah"></div>
RELOAD<br>
LOGIN<br>
LOGOUT<br>
FRIENDS
There was a problem with the build system and the test containers. If you build an adHoc version of your software it should work. However, all my "test anywhere" helper applications also still have the bug for the time being.
There should be an update to the test containers shortly that should fix the problem. I'll try to post back here once they have been updated.

Categories

Resources