#development
1 messages Β· Page 865 of 1
was
ya
which editor
i need a free thing to put my code in the bot
Put your code in the bot β
I think you have the wrong idea of bot making
well
Tons of free python tutorials out there, check it out
Search up Python IDE
ok
^
Use vscode
If you search a text editor to code: Sublime Text, Visual studio code π
Vscode is dashing ;)
You should not start by programming bot if you've never coded before
You are gonna need to learn the basics first
@velvet zenith search like freecodecamp python tutorial on youtube and you'll find some good things!
ok
xd a little off topic ima youtuber
anyways
can someone give me the code for a dm bot
OK

that isnt js right?
is typing
i could send a post request on a webhook every 10sec and i will not trigger the rate limit?
@regal saddle it's json out put
Json with list?

No
Json output be like json { "guild.id": { "msg.author.id": { "text" : "id", "voice": "id" } } }
YES I KNOW
It's been 3 times you repost it
Well do code
I am using Glitch to do some tests on my bot, the code has no errors, but the bot does not come online? What could be the problem?
Token
@tight plinth The token is right, I have also regenerated a new token
Show code
using the guilds scope, what's the best way of getting partial guild info for a single guild
i.e. /users/@me/guilds will not work because i cannot specify one snowflake
@fleet chasm @regal saddle I'd like you two to think about what this chat is for rather than shit posting:
#development and #topgg-api are NOT the place for shit posting and in general being unhelpful, you have no right to mislead people or troll people who are new regardless of how much or how little prior experience they have.
In the 25 minutes I watched this chat and attempted to help someone who, yes they did not know what they were doing the 2 of you did not help the situation at all I donβt care what you say in off-topic but if you have nothing useful to contribute donβt say anything at all, when someone asks to be spoon fed tell them βNo, we wonβt do that for these reasonsβ¦'' Don't be that person who says βsure I'll give you the codeβ only to troll that person, it is not fair on them.
All you do when doing that is confuse them and make it harder for the people who are actually trying to help explain.
TL;DR = If you have nothing productive to say in #development or #topgg-api don't say it at all, donβt be that asshole who trolls and mocks people simply trying to learn or achieve something.
Aimed mostly at lukas 
k sir
You should not start by programming bot if you've never coded before
@modest maple well, it actually worked to me
my first encounter with coding was with discord bots
same
is glitch on debian or ubuntu
run neofetch and see for urself lol
@peak quail yes also webhooks are special and they can send multiple embeds in one message
hi, i'm using open source nadeko, and i was wondering how I would go about changing the .kick command to send an embed to a specific channel when it's used?
essentially logging it, but without having to mess with the logging system it already has
#nadeko-modding in https://discord.nadeko.bot/
If they ain't able to help, I don't think we will be
not that they weren't able to, they just don't lmfao

bot.on('message', message => {
let preId = "698950081038254240"
if(!message.guild.member.find(preId)) return;
if(message.content === `${prefix}help`) {
let helpembed = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("asd")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Commands!").then(message => {message.delete(6000)});
message.author.send(helpembed);
}
else if(message.guild.member.find(preId)) {
let helpembedpremium = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Gay")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Premium Commands!").then(message => {message.delete(6000)});
message.author.send(helpembedpremium);
}
});```
anyone know how to make this a valid function
I want it to find a certain user id. And if the certain id is in the server, then the member running the command will get sent a completely different embed
---------------
The ID of a certain bot. So if the ID of a certain bot is PRESENT in the server, then anyone running the command will get sent the else statement embed, in this case "**Gay**"
But if the ID of a certain bot isnt PRESENT in the server,then anyone running the command will get sent the main statement embed, in this case "**Asd**"
.find takes a function, with the first argument being a GuildMember. So, pass a function and check the member's User object and see if their ID matches. If it does, do whatever you plan on doing.
Though, wouldn't you mean something like if (the member with the id was found) {...} else {...}?
also members.find, not member.find
members.find wouldn't work
I tried it gave an error
11
if (typeof value === 'undefined') throw new Error('Value must be specified.');
^
Error: Value must be specified.
thats the error
if i use members.find
it should be message.guild.members.find(preId)
bot.on('message', message => {
let preId = "698950081038254240"
if(!message.guild.members.find(preId)) return;
if(message.content === `${prefix}help`) {
let helpembed = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Commands!\n\n1. -clear \n2. -ask (Question) {8ball CMD}\n3. -members\n4. -server\n5. -suggest\n6. -meme\n7. -botinfo\n8. -invites\n9. -blacklist {on/off}\n(This prevents discord links from being sent!)\n\nPage 1 >> (-page 2) in dms")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Commands!").then(message => {message.delete(6000)});
message.author.send(helpembed);
}
else if(message.guild.members.find(preId)) {
let helpembedpremium = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Gay")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Premium Commands!").then(message => {message.delete(6000)});
message.author.send(helpembedpremium);
}
});```
isnt that what i did
You should be passing a function?
if(!message.guild.members.find(m => m.id == preId)) return;
^
TypeError: Cannot read property 'members' of null
why is message.guild null?
oh yea
Dms
no guild makes it null

yeah it needs to be in a guild channel
Well if it's trying to get the dm channel or message guild will always be null
/home/container $ node app.js
/home/container/app.js:1223
client.channels.get(698983333782093925).send('ββββββββββββββββββββββββββββββββββββββββββββββββββββ \nServer: ' + message.guild.name + ' \nChannel: ' + message.channel.name + ' \nUser: ' + message.author.username + ' \nMessage: ' + message.content')
^^
SyntaxError: Invalid or unexpected token
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
``` π€ Error... (It's for logging)
line 79
thats why if(!message.guild) return;
is that one line?
Yeah?
Isn't it because the snowflake is given as an int not string?
Don't you need to put "" around it
I usually just newline my code after a "\n" visual studio auto adds the extra + "
this is the whole new code
bot.on('message', message => {
if(!message.guild) return;
let preId = "698950081038254240"
if(!message.guild.members.find(m => m.id == preId)) return;
if(message.content === `${prefix}help`) {
let helpembed = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("ASD")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Commands!").then(message => {message.delete(6000)});
return message.author.send(helpembed);
}
else if(message.guild.members.find(m => m.id == preId)) {
let helpembedpremium = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Gay")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Premium Commands!").then(message => {message.delete(6000)});
return message.author.send(helpembedpremium);
}
});```
Still the same error?
Wait why are you not checking if the message starts with the prefix?
const result = request(`${this.path}/set`, {
method:'post',
body: {'key':a, 'value':b},
headers: { 'Content-Type': 'application/json', 'authorization': this.password }
})```
Req.body is {} and not "{key....}"
```js
this.app.post("/set", async(req,res) => {
if(req.headers.authorization == this.password) {
console.log(req.body)
res.send(await db.set(req.headers.key, req.headers.value))
} else {
res.send("Unauthorized")
}
})```
I mean this bit
But it's not the prefix command is 1 if but the else if will always run on a message
It sends them both
You have been dmed a list of Commands!
You have been dmed a list of Premium Commands!
Funky
if(message.content === ${prefix}help) {
}
else if(message.guild.members.find(m => m.id == preId)) {
}
welp
NOPE
The else if will always run without a prefix and command
The formatting should explain itself right?
It spams my chat with
You have been dmed a list of Premium Commands! Everytime i run the command
You forgot to close your string somewhere
have you tried putting β;β at the end
bot.on('message', message => {
if(!message.guild) return;
let preId = "698950081038254240"
if(!message.guild.members.find(m => m.id == preId)) return;
if(message.content === `${prefix}help`) {
let helpembed = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Commands!\n\n1. -clear \n2. -ask (Question) {8ball CMD}\n3. -members\n4. -server\n5. -suggest\n6. -meme\n7. -botinfo\n8. -invites\n9. -blacklist {on/off}\n(This prevents discord links from being sent!)\n\nPage 1 >> (-page 2) in dms")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Commands!").then(message => {message.delete(6000)});
message.author.send(helpembed);
return;
} else if(message.guild.members.find(m => m.id == preId)) {
let helpembedpremium = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Gay")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Premium Commands!").then(message => {message.delete(6000)});
message.author.send(helpembedpremium);
return;
}
});```
I closed it
tho
You're not checking the prefix and command correctly
Uh @true ravine
/home/container $ node app.js
/home/container/app.js:1223
client.channels.get('698983333782093925').send('ββββββββββββββββββββββββββββββββββββββββββββββββββββ \nServer: ' + message.guild.name + ' \nChannel: ' + message.channel.name + ' \nUser: ' + message.author.username + ' \nMessage: ' + message.content')
^^
SyntaxError: Invalid or unexpected token
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
message event for every command
Delete this '
Okay?
Timo
Owh yeah Im dumb forgot that xD
Dm me
You need to be checking if the message starts with the prefix and return if it's not
It's not
if(message.content === ${prefix}help) {
}
else if(message.guild.members.find(m => m.id == preId)) {
}
hes checking the prefix, then running the other code if no prefix
The else if will run regardless of prefix and command except for the fine role
the other code always runs
^
i was afraid of my dog crapping om my floor when i went to take a shower s i took her with me and when i came back she had made a bed out of one of the mats
@wide wharf show your code
pork
@quartz kindle Uh
/home/container $ node app.js
/home/container/app.js:1224
});
SyntaxError: Unexpected end of input
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
``` ^^^^^^
So it turns out my entire bot script was deleted
Im depressed now
Owh
It was just completely overwritten
client.on('message', message => {
if (!message.guild) return;
client.channels.get('698983333782093925').send('ββββββββββββββββββββββββββββββββββββββββββββββββββββ \nServer: ' + message.guild.name + ' \nChannel: ' + message.channel.name + ' \nUser: ' + message.author.username + ' \nMessage: ' + message.content)
``` @quartz kindle^^^^
ngl, poop
show more code
Uh but there must be the error... cuz thats the new code
if(!message.guild.members.find(m => m.id == preId)) return;
^
TypeError: Cannot read property 'members' of null
bot.on('message', message => {
let preId = "698950081038254240"
if(!message.guild.members.find(m => m.id == preId)) return;
if(message.content === `${prefix}help`) {
let helpembed = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Commands!\n\n1. -clear \n2. -ask (Question) {8ball CMD}\n3. -members\n4. -server\n5. -suggest\n6. -meme\n7. -botinfo\n8. -invites\n9. -blacklist {on/off}\n(This prevents discord links from being sent!)\n\nPage 1 >> (-page 2) in dms")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Commands!").then(message => {message.delete(6000)});
message.author.send(helpembed);
} else if(message.guild.members.find(m => m.id == preId)) {
let helpembedpremium = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Gay")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Premium Commands!").then(message => {message.delete(6000)});
message.author.send(helpembedpremium);
};
});```
It also sends both instead of one
thats what i thought
can yall help me
good that you found it
dont care didnt ask
btw that code will result in an error
Thx π
wait no
Million ik
if(!message.guild.members.find(m => m.id == preId)) return;
^
TypeError: Cannot read property 'members' of null
bot.on('message', message => {
let preId = "698950081038254240"
if(!message.guild.members.find(m => m.id == preId)) return;
if(message.content === `${prefix}help`) {
let helpembed = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Commands!\n\n1. -clear \n2. -ask (Question) {8ball CMD}\n3. -members\n4. -server\n5. -suggest\n6. -meme\n7. -botinfo\n8. -invites\n9. -blacklist {on/off}\n(This prevents discord links from being sent!)\n\nPage 1 >> (-page 2) in dms")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Commands!").then(message => {message.delete(6000)});
message.author.send(helpembed);
} else if(message.guild.members.find(m => m.id == preId)) {
let helpembedpremium = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Gay")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Premium Commands!").then(message => {message.delete(6000)});
message.author.send(helpembedpremium);
};
});```
It also sends both instead of one
It shows the error above
I was talking to ProCrafter tbh
oh
but I didnt see a line
@calm shore did you actually do the changes you were suggested?
properly check for prefix
several people gave you things to do
im not being rude, i want to see if you changed your code, because youre showing the same old code without any changes
i need to see your current updated code
I tried what you suggested and it didnt work so i reverted back to the original
then we're back to the same problem
also Wobbly, when you create a variable that is 2 words, its common to capitalize the 2nd word's first letter
we have to fix it one step at a time
no
Ohhh ik what you mean
not exactly
So that it does not trigger on anything but commands
you have a startsWith functon you can use
you have this ```js
if(message.content === ${prefix}bla) {
// do something
} else if(members.find(bla)) {
// do something else
}
if you do that, you will have a piece of code that will ignore the prefix and attempt to run on messages without prefix or command
I changed it to this
bot.on('message', message => {
if(!prefix) return;
let preId = "698950081038254240"
if(!message.guild.members.find(m => m.id == preId)) {
if(message.content === `${prefix}help`) {
let helpembed = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Commands!\n\n1. -clear \n2. -ask (Question) {8ball CMD}\n3. -members\n4. -server\n5. -suggest\n6. -meme\n7. -botinfo\n8. -invites\n9. -blacklist {on/off}\n(This prevents discord links from being sent!)\n\nPage 1 >> (-page 2) in dms")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Commands!").then(message => {message.delete(6000)});
message.author.send(helpembed);
}
} else if(message.guild.members.find(m => m.id == preId)) {
if(message.content === `${prefix}help`) {
let helpembedpremium = new Discord.RichEmbed()
.setAuthor("Teht")
.setColor("#ff7600")
.setDescription("Gay")
.setFooter(` β€οΈ Teht - Thank you for Joining Us!`);
message.channel.send("You have been dmed a list of Premium Commands!").then(message => {message.delete(6000)});
message.author.send(helpembedpremium);
}
};
});```
11
client.on('message', message => {
if (!message.guild) return;
client.channels.get('698983333782093925').send('ββββββββββββββββββββββββββββββββββββββββββββββββββββ \nServer: ' + message.guild.name + ' \nChannel: ' + message.channel.name + ' \nUser: ' + message.author.username + ' \nMessage: ' + message.content)});
``` @quartz kindle How can I do that the bot doesn't send messages of server with id (...) ?
what spam?
Anyone know what the process exit number is to restart a discord.js bot
it was deleted
@calm shore good, a bit wonky but it will work. now add an if(!message.guild) return at the beginning
yes, I understand, I dont think he meant to though
@wide wharf if(message.guild.id === "id") return
Ty!!
Wait is it even possible to reload bot using process.exit
yes if you have a process manager or an external monitoring process
I tried process.exit(1) but that just stops the bot
()
that will only relog the bot
you would need to put you event and command handler in that ready event as well as everything you want to happen at start iirc
require('child_process').exec('refresh');
that works?
yes
so i replace the process.exit with that
I did not get it to work
are u using an eval cmd?
I did test with eval
it didnt?
no
hmm
it only works for some domains
like glitch

client.destroy() without a rebooter = ded
Iβm sorry but if your still using glitch and not like vs thatβs kinda wonky
yea
How can I change the name of a channel that I specify via id (discord.js)?
who said I am
other way around
half of the server does
client.destroy()
client.login()
^
Simo you need to fetch or grab the channel then you need to rename it
destroy then login will restart the discord connection and state, but not the process
boys times up big boy tim is here
@crimson vapor I know the channel id that i want rename
so you can either fetch it or grab it from cache
use get
works π
then you use the function to rename it
client.destroy()
client.login('token here')
i just put an embed before it saying 'Restarted'
yes but that would not really do what you want in most cases
you would need to reload ALL of your commands
and I Think you need to add back all of your events
for some reason, i get an error in my console saying 'discordapierror'
what error?
discordapi
yes but what is the error?
if someone wants to unban someone, they can still ping them when they are banned
lemme see
value <userid> is not snowflake
because the person tries to unban the user by mentioning the banned user
im not sure why discord lets us mention banned users
mentions are global
also
they resolve differently to each user
if I save my code and use that client.destroy and client.login, will it update the bot to that code
u cant mention a member who is not cached in ur discord app
you can
or fails to cache it
@royal portal no
so if i save my code and use restart cmd it wont update the code?
nope
r u using a vps?
Any mongoDB users that can help me out??
with?
sure what do you need Jaay
π
So I've been working on my bot for a while and recently I've been told to increase my Pool Size for the bot but I wasn't sure what to increase it
does anyone know what exactly client.destroy and client.login does
for like a restart command
@royal portal i told you what it does
it destroys the discord library and resets its state, then recreates it and logs in again
sorry Jaay, I dont know about Pool Size
Ahh okay that's fine I'll just keep on researching and trying to find the best option then β€οΈ
pool size depends on how you use mongo, which library, which connection method, etc
Ahh okay
im gonna set up a bot
for 24/7
and see if it breaks
well if the status breaks
because when i try to host bot
status works for like 30 mins
when doing process.cpuUsage();
what do these numbers actually mean? They have no real meaning to me
{ user: 329382193, system: 48866771 }
the user is an integer represents the time elapsed by user
the system is an integer represents the time elapsed by system
can someone help me with just, coding a bot in general? because i dont know anything about how to do it
i cant find any reliable source to learn, because their code never works
If you dont know the language that you plan to code in, I would recommend starting there
i use python 3.6
Do you have a general understanding for how it works?
wym?
Do you understand python. Can you code in regular python
without the use of i think d.py
i think thats the library for python
kinda, just really basic stuff
Well, I would recommend learning a bit before moving onto making a discord bot, as if you don't you wont really be learning anything and youll just be writing down what other people have done
Not sure, i code in nodejs
so
Β―_(γ)_/Β―
Heres a page from a quick google search though
should i just go with java?
I mean, if you want to learn Java then sure
yea, because everyone uses java anyways
if u want to focus on making discord boys as a beginner
js
coz it has more docs and guides
@icy crane They are in microseconds as well (https://nodejs.org/api/process.html#process_process_cpuusage_previousvalue)
lmao
Alright, do you know of an easier way to calc cpu usage? Cause I used one method, but it ended up not working as it was just getting higher and higher as time went on
@quartz kindle does the client.destroy and client.login reset setActivity too?
can i detect who is updated channel by using .on(ChannelUpdate with discord.js v11
Yeah it's time, it goes up the longer it's running, are you looking for % cpu usage?
Yeah
Ive tried different things, and even resorted to just straight up googling it cough cough stack overflow
, but everything that ive tried just gets higher with time
@icy crane i couldn't see anything about the user who updated the channel on that docs page
Then you probably can't
https://www.npmjs.com/package/node-os-utils look at this
may help for what you want
but I don't think it's per process
lol theres so many os packages, i have the default one, "os" then "os-utils" and now "node-os-utils"
@vivid cargo he meant what is client defined as
When I run my command, nothing happens and there is no error logged. Can anyone help?
https://pastebin.com/X1CTXvtZ
all of the "stuff" is replaced text for simplicity
first remove this
const bot = new discord.Client();
then show how you call that function, ie: where you do command.run()
is there a way to set bot activity after client.destroy and client.login
should be the same way as before
it has to be in the ready event
so is it not possible to do it by message?
how would I make it do the ready event when I reload
@amber fractal sorry for the ping, but I just wanted to thank you! Works great!
you want to set a different presence than you set before?
π
no I want it to show the status when reloaded
the ready event should still work after re-logging in
it doesn't
so it should pick up the same code from there
i dont know why but it doesnt even do the console.log in ready when i restart
can you console.log(client._events) after destroy and login?
only when I start bot it does it
lemme see
Object: null prototype
ready: function
message: function, function, asyncfunction, asyncfunction, function, function, asyncfunction
so the events are still there, the ready event should fire again
not sure why it doesnt
can you show your full code?
for restart?
for restart and the main file
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("with discord.js");
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.on("message", message => {
if (message.author.bot) return;
if (message.channel. type === 'dm') return;
if (message.author.id !== '364836696149458944') return;
if (msg.content === 'restart') {
msg.reply("Restarted.");
client.destroy();
client.login('token');
console.log(client._events);
}
}
});
client.login('token');
a
why do you have 2 message events?
how do i get guild usercount?
what lib
guildObject.members.size
guildobject?
is this a command or what
wats da const
what
you switch guildObject with
whatever guild object u have
like message.guild
or sometihng
So im trying to link my bot to roblox and get a roleID of a certain group from a role name
Im using nobloxjs
https://github.com/suufi/noblox.js/wiki/Group-Functions#getrole
message.channel.send(id)
})``` id returns false
its supposed to return an object
if you merge branches, github replaces the whole file with the new file, right?
tim i sent code
@royal portal so apparently the client does indeed remove the events but forgets to clean them up in client._events somehow
i cant find the source code for this, but i tested it
like say if old file is ```js
let hello = 3
let s = 2
hello + s + 3
and new file is ```js
let s = 2
s + 3
will the final file be just what the new file is, or the origional as newfile is a subset of it
so you do need to rebind/re-add all the events
how would I do that
i assume it replaces but idk this conflicts thing makes things confusing
i can't add the events after client.login
it is
nevermind
then why do u need top add events after it
because it removes it
im trying to use setActivity after client.destroy and client.login
you can probably hack it like this js for(let event in client._events) { client.on(event,client._events[event]) }
i didnt test this tho
afaik doesnt matter, as long as its after destroy()
event is not defined
for(let event in client._events)
i forgot the variable declaring
i wrote for(event in event._events) {
hm lemme see for(let event in client._events)
wrote events instead of event
events?
I mean event
there is no variable named events
for(let event in client._events) {
client.on(event,client._events[event])
}
ah
i would need to make it then
I meant
"listener" argument must be of type function. received an instance of array at checklistener
client._events[event] doesn't return a function.
Like the error states. It's returning an Array.
so what would I do to make 'listener' argument a type function
Use the console?
See what works best for you.
for (const event of client._events)
{
console.log(client._events[ event ]);
}```
client.on(event, typeof client._events[event] === "function" ? client._events[event] : client._events[event][0])
@royal portal im testing it here but i cant figure out what exactly the destroy() function is doing, it seems to me that it leaves behind a dirty client
for example, the client status is still marked as "ready" after using destroy()
yeah
so the ready event will not fire again
im not sure of another way to restart bot
but to fire event again
if i were you i would not even attempt to do what you're doing
it makes no sense in the first place
okay
everyone does it the process way
process.exit?
would i use process.exit
Yes
but then that will just exit
Hence why I said use pm2.
thats what i told you in the very beginning on this conversation
use a process manager
or a monitoring process
child_process.exec()
Close enough
@royal portal once a process is dead, its dead and thats it. it cant magically restart itself, it needs help from outside. a process manager can do such things, like monitor your process and auto-restart it when it closes
most solutions out there, like pm2, dont require extra code
im not sure how to use pm2 in the code
with pm2 for example, you just need to install it, then run pm2 start index.js, instead of node index.js
oh
npm i pm2 --save
npx pm2 start index.js
so i dont node my code
you probably want -g
or globally
for global pm2
you can read all about it here
so is it possible to add the pm2 code after the restart message
Yes.
there is no need for that
instead of running your bot as a single node process, you make pm2 run it instead, and let pm2 take care of managing it
then your process will run inside pm2
once running in pm2, every time it exits, it automatically restarts
so for my restart
so you can just do process.exit() in your restart command
Don't you need a flag for that to be possible?
What command?
run it in the terminal?
did you install pm2?
And it's running?
how are you running it
pm2 start <botfile>.js
oh
not quite
so i wrote
pm2 start bot.js
and
i saved it
as pm2.js
then in terminal i did
what
Hmm???
pm2 start 0
you dont need to save any file
Have you done npm i -g pm2?
Why?
wth?
and it has the command in it
you have to install it as a global installation, with the -g option
you dont need to create any file
Otherwise you need to use npx or filepath it.
stop doing weird things on your own and listen to us lol
i'll do npm i -g pm2
yep
now what
wait, kinda just jumping in, if you do process.exit() or whatever, pm2 will auto restart it?
Yeah should do
Yes @icy crane
pm2 logs
Alright
ok
pm2 start 0
0 should already be started
it started
Do pm2 logs
Hi, who knows a bot that puts a reaction to every message in a specific channel?
why?
That's not a good idea for a bot due to rate limiting.
i checked logs
it had too many unstable restarts
16
stopped.
missing ) after argument list
That's an error in your bot code.
its for process.exit
You need () after process.exit
process.exit();
}
})
}
});
What??
anyone here use atom
I "used" to use Atom.
if so, the env file isnt coloured, would thta mean anything?
is it
Normal
Most likely not.
process.exit();
}
})
});
It's not coloured in many editors.

:)
just wondering
noob, i thought i was in off topic 
or do I need to add something after
/sheug
F
Maybe u got a different theme?
seems like glitch is one of the only ones that has it coloured 
@royal portal you need to show a proper code block that includes the entire function you want to fix, else we dont understand anything you're saying
Nope

vim has it defaulted
well
time to update my bot
when i first got the vps i had no idea i needed dotenv, so when .env didnt work i resorted to a env.js file 
dotenv isn't needed
It's handy for when you upload to github tho
You just need to put the environment variables into env
Good.
that wasnt the case for me then
export TOKEN="token"
but where does .catch go to
holdon what
does it log it in the pm2 logs

no
ah ok
Fair
the only thing is
missing ) after argument list
add a )
Wow, I just discovered pm2 monitor
That's awesome
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("with discord.js");
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.on("message", msg => {
if (message.author.bot) return;
if (message.channel. type === 'dm') return;
if (message.author.id !== '364836696149458944') return;
if (msg.content === 'restart') {
msg.reply("Restarted.");
process.exit();
};
});
client.login('token');
Oml the indents
yeah
Use something like eslint
wtf
yes
like that?
how to remove from list
pm2 start 0
but its deleted
pm2 start bot.js
Why would you delete it?
pm2 is wonky with package changes
errors
What error?
missing ) after argument list
sometimes i update or change a package and do pm2 restart, and the old packages are still being used
for the thing you said
Show code again.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("with discord.js");
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.on("message", msg => {
if (message.author.bot) return;
if (message.channel. type === 'dm') return;
if (message.author.id !== '364836696149458944') return;
if (msg.content === 'restart') {
msg.reply("Restarted.");
process.exit();
};
});
client.login('token');
its the }; part
remove the semi colon
Shouldn't matter
i did
yikes
still
i fixed it
and
still same thing
wait
thats because
i still have
client.login
.-.
?
because i copied code from rpi
missing ) after argument list
Which line?
the }
You might want to add a .then or await to your message.reply
then you need to post your current code
ok
as process will call at the exact same time.
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("with discord.js");
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.on("message", msg => {
if (message.author.bot) return;
if (message.channel.type === 'dm') return;
if (message.author.id !== '364836696149458944') return;
if (msg.content === 'restart') {
msg.reply("Restarted.");
process.exit();
}
});
client.login('token');
message.reply('Restarting...').then(() => process.exit());
Why do you have two message events...?
can you post the full error?
ok let me email myself that
?
wt
Are you on mobile or smth?
Control right click it
Just take a pic
even mobile lets you long press, select and copy
Oh
Oh
@royal portal how are you accessing/viewing your rpi?
Just ssh to it?
Putty?
If you're on the latest version of windows there isn't a requirement for putty
Unless that's just a 'pro' thing
Snowflake works good for me :)
0|bot | /home/pi/Desktop/Other/DiscordBot/bot.js:19
0|bot | }
0|bot | ^
0|bot | SyntaxError: missing ) after argument list
0|bot | at wrapSafe (internal/modules/cjs/loader.js:1072:16)
0|bot | at Module._compile (internal/modules/cjs/loader.js:1122:27)
0|bot | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
0|bot | at Module.load (internal/modules/cjs/loader.js:1002:32)
0|bot | at Function.Module._load (internal/modules/cjs/loader.js:901:14)
0|bot | at Object.<anonymous> (/home/pi/.config/nvm/versions/node/v12.16.1/lib/node_modules/pm2/lib/ProcessContainerFork.js:32:23)
0|bot | at Module._compile (internal/modules/cjs/loader.js:1158:30)
0|bot | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
0|bot | at Module.load (internal/modules/cjs/loader.js:1002:32)
0|bot | at Function.Module._load (internal/modules/cjs/loader.js:901:14)
message.reply line
it isnt
According to the code block you sent line 19 points to the msg.reply line.
i dont get whats wrong with it
Oh I bet it's due to that indenting
yeah
js doesnt care about indentation
the last code you posted has nothing wrong as far as i can see
so if i do
message.reply('Restarting...').then(() => process.exit());
unexpected token )
message.reply('Restarting...').then(() => process.exit());
for that part
that I made bold
if I remove it, should work
Can someone help me with this?
https://pastebin.com/veGfjSX5
jesus where's darkmode?
I asked earlier and changed a few things, but I'm still getting nothing with no errors
its just that }
so many rows without semicolon... ree
on mine?
no
on mine?
nah, Sbss
JS isn't bothered for semi-colons
i know, it's stil triggering me π
Yeah
now about
//FS Reading
fs.readdir("./Commands", (err, files) => {
if (err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if (jsfile.length <= 0) {
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) => {
let props = require(`./Commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props)
})
});
//Command Starter
bot.on("message", async message => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
let prefix = ">";
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
let commandfile = bot.commands.get(cmd.slice(prefix.length));
if (commandfile) {
if(cmd.startsWith(prefix)) {
commandfile.run(bot, message, args)
}}});```
if (message.content === 'restart') {
if (message.author.id !== '364836696149458944') return;
message.channel.send('Restarted.').then(() => {
process.exit(1);
})
};
Yea
would that work
Yeah
but then wouldnt i need }) to close it off
@royal portal want to restart the bot?
Why?
Using pm2?
yea
client.on('message', function(msg) {
// checks
// commands
if (msg.content == 'restart') {
if (msg.id == 'id')
msg.reply('Restarting...').then(() => process.exit());
}
});```
@warm marsh process.exit(1)
Is it tho?...
Yes
Hmm if it doesn't work then add that 1 anyway
Hmm ok...
Typical js
but
Get a linter
it still works
I also have a command like that but it's only for shuting down the bot
@royal portal the only explanation for that is that you didnt show your full code
you either left something out of it, or you posted an outdated code
Also don't use multiple message listeners for commands that's a very inefficient way.
And considering the default max is 10. You can only get 9 commands and ready listener.
@royal portal also, just to confirm, are you doing pm2 restart everytime you update your code?
why --watch
pm2 start bot.js --watch
does it like update code everytime i save
Yes
and restart
Is there any other module that can restart the bot?
Because i can't install pm2 on my Termux on my phone lmao
Lmao
here's the code
client.on("message", message => {
if (message.author.bot) return;
if(message.channel.type === "dm") return;
if (message.author.id !== '364836696149458944') return;
let prefix = "-";
if (message.content.indexOf(prefix) !== 0) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "restart") {
const embed = new Discord.MessageEmbed()
.setDescription(":computer: Restarted.")
.setColor(0x00AE86)
message.channel.send(embed).then(() => process.exit());
}
});
Idk in termux but there is alternate ways.
not on that code
all of my code
like after client.login line
right at end of whole code
it says 207 line
but i didnt write anything in that line
of what file
@royal portal you're missing either a bracket or parentheses or something
send the whole error
@royal portal when the error is on a non-existent line at the end of the file, the real problem is a missing ) or } somewhere in the file. it can be anywhere
thats why you need to post the FULL code
the entire file
a linter would also help here
He is missing either } ) or something or he misplaced them
use hastebin and send all the code in the file excluding token
Yea that would help
Can someone help me with this?
https://pastebin.com/veGfjSX5
@gritty bolt
This is my FS code```js
//FS Reading
fs.readdir("./Commands", (err, files) => {
if (err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if (jsfile.length <= 0) {
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) => {
let props = require(./Commands/${f});
console.log(${f} loaded!);
bot.commands.set(props.help.name, props)
})
});
//Command Starter
bot.on("message", async message => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
let prefix = ">";
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);let commandfile = bot.commands.get(cmd.slice(prefix.length)); if (commandfile) { if(cmd.startsWith(prefix)) { commandfile.run(bot, message, args) }}});```
@gritty bolt
@gritty bolt what is the problem again?
No error
Does any command run?
ok
i think its down
then use some other bin
i had the same issue, hence why i used pastebin
@royal portal how long is your code lol?
0bin is a client-side-encrypted
pastebin featuring burn after reading, an history and
a clipboard
i got it
@quartz kindle
you posted your token
im stupid i used the wrong number of args
correct
@royal portal i literally saw no Missing } or ) or anything else...
And also why are you making a message event for every single one of your commands? Isn't just one enough?
Hmm... Something is 100% missing but i wasn't able to find it...
oh
ya
fixed
it just shows old error log
why
@blazing portal thanks for finding that mistake
@royal portal can you show us what did you edit?
you're welcome
thats a bitwise OR operator
no i mean
it shows
my token error when i changed token
the token is right now
kitty-error.log last 15 lines
Oh ok
Lol
and also
can someone help me
on my unban cmd
client.on("message", async message => {
if (message.author.bot) return;
if(message.channel.type === "dm") return;
let prefix = "-";
if (message.content.indexOf(prefix) !== 0) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "unban") {
if (!message.guild.me.hasPermission('BAN_MEMBERS')) return message.channel.send('Error: I don\'t have the permission to unban members.');
if (!message.member.roles.cache.some(role => role.name === 'Server Administrator')) return;
let bannedMember = await client.users.fetch(args[0]).then().catch(console.error);
if(!bannedMember) return message.channel.send("Please provide a userID to unban someone.")
let reason = args.slice(1).join(" ")
if(!reason) reason = "No reason given."
let logsChannel = message.guild.channels.cache.find(ch => ch.name === "mod-log");
let embed = new Discord.MessageEmbed()
.setTitle('Unban')
.addField('User', `${bannedMember.tag} (<@${bannedMember.id}>)`, true)
.addField('Moderator', message.author.tag, true)
.addField('Reason', reason)
.setColor("#00ff00")
.setTimestamp();
if(!message.guild.me.hasPermission(["BAN_MEMBERS", "ADMINISTRATOR"])) return message.channel.send("Error: I don't have permission to perform this command.")|
message.delete()
try {
message.guild.members.unban(bannedMember).then().catch(console.error);
logsChannel.send(embed).then().catch(console.error);
} catch(e) {
console.log(e.message)
}
}
});
What's the issue?




