Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  48] [ 4]  / answers: 1 / hits: 55956  / 6 Years ago, tue, january 16, 2018, 12:00:00

Making a discord bot. Everything works fine, except the one command of -!prefix. -! being the prefix, and the command taking the args and changing the prefix of the server.



Before I go into detail about this while thing, here's the bot's code, maybe I simply did something wrong in the consts: Hastebin Link



The error here is in line 52, according to the console: Console Log



I'm confused as to what to do with this being undefined. I've tried using the message.guild.id property as the variable, and also the one shown on the code. I've tried moving it to multiple places, although the only place it even registers is INSIDE of the prefix command (which is currently broken because of this error.)



Anyone have any fixes? I'm not that much of an expert in the whole JavaScript thing, as I came over from Python and regular Java.


More From » discord

 Answers
2

Your code at line 52 is currently:



var server = bot.guilds.get(message.author).id


You're currently passing a User object into the .get() which should recieve an id or snowflake.



With this in mind, your code should look like:



var server = bot.guilds.get(message.guild.id).id;


However, this is a bit excessive because you can simply shorten it to:



var server = message.guild.id;


Now you said that you've




tried using the message.guild.id property as the variable, and also the one shown on the code.




I'm not sure if you mean what I just suggested, but if so please notify me.


[#55452] Friday, January 12, 2018, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reesel

Total Points: 345
Total Questions: 124
Total Answers: 119

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
;