#development
1 messages ยท Page 337 of 1
If you have a way to trigger the bot via a mention, you may want to add a filter for the bot itself
message.mentions.members.ban("Being a bad person")
message.mentions.members.forEach(member => member.ban());
if (message.guild) {
message.mentions.members.filter(member => member.id !== message.client.user.id).forEach(member => member.ban());
} else {
message.reply('You Bigot, you need to be in a guild');
}
Check if you're in a guild first
Ah
Or else your bot will crash
This is the code that does the actual banning
message.mentions.members.forEach(member => member.ban());
However, it will not work outside a guild
The filter just ensures it doesn't try to ban itself
It can't, but it's better to add it in, because errors will pop up when you try
What ID obtaining?
.filter(member => member.id !== message.client.user.id)
That doesn't do anything about banning
Yes
๐คฆ
If it is not the client ID, it will be kept on the list of things to ban
Ahhhh!
Alright!
This makes sense!
Wait
Wouldnt you want the client ID on the list to ban?
Nvm
You mean the bot client ID
Derp
Well, wow thank you!
Sorry about last time
Lol its fine bro
I was really angry at how long it takes for others to understand code, but you've grown better since last time
Rip and aw thx lol
could someone tell me why this always returns undefined?
client.getUser = id => {
client.rethink.db('best').table('users').get(id).run(client.connection, (err, result) => {
if(err) return console.error('Error while fetching a user from the database\n' + err);
return result;
});
};
both the table and the db exist
discord.js
No clue
<Client>.guilds.size
So like bot.on('ready', () => { <Client>.guilds.size.console.log });?
Oh
Im really smart
as you can tell
So bot.on('ready', () => { bot.guilds.size.console.log });
I can try both
TypeError: Cannot read property 'log' of undefined???
Got it to work
BREAKTHROUGH ๐ ```rb
server = IO.popen('server.exe', 'r+')
bot.command(:update) do |event|
server.puts('givemoney ' + $save[event.user.id.to_s].steamid? + ' ' + $save[event.user.id].money)
event.respond 'Balance updated!'
end```
?
System.out.println("123");```
@tawny lava do yourself a favor and use rethinkdbdash instead of rethinkdb
It's better in alot of aspects, less cluttered. You don't need to pass your connection with each call, you don't need to fuck with cursors
meanwhile the java driver hardly works and its last release was years ago
kill me ^^;
sql.get(`SELECT * FROM cases WHERE guildId =${msg.guild.id}`).then(row => {
if(!row) {
return;
} else {
var number = row.number;
//values cant be returned here
});
//values can be returned here
}```
Returning `number` says undefined so idk how to get that variable returned where values can be returned 
What are you trying to do with that coding?
@thorny hinge That is because row.number does not exist
row.length will return the amount of rows
I can see the chat through my bot.... It's weird 
you want to use var number = row[0].number
also, use if (row.length < 1) { instaed of if (!row) {
Hi
That wasnt my problem, its just that I cant use the variable in the //values can be returned section 
Because its outside of the sql thingie
Promisify all the things 
@thorny hinge
function getCase() {
return new Promise((resolve, reject) => {
sql.get(`SELECT * FROM cases WHERE guildId =${msg.guild.id}`).then(row => {
if (row.length < 1) return reject();
resolve(row[0].number);
});
});
}```
Then to use that, use this
getCase().then(caseNumber => {
// use caseNumber
}).catch(() => {
// could not get case
})```
thanks
no problem
also, you may want to sanatize your database input
although it's not user input, it's still good practice
ยฏ_(ใ)_/ยฏ
Alright
๐
@earnest phoenix prepared statements
Yeah, whatever it's called
const https = require('https');
const postData = JSON.stringify({
server_count: bot.guilds.size
});
const options = {
hostname: 'https://discordbots.org',
path: `/api/bots/${bot.User.id}/stats`,
method: 'POST',
headers: {
'User-Agent': 'DiscordBot (https://moustacheminer.com/) Discord Guild Counter',
'Content-Type': 'application/json',
'Content-Length': postData.length,
Authorization: 'X'
}
};```
Whats wrong with it? I get the error TypeError: Cannot read property 'id' of undefined.
Im using discord.js
what line is causing the error
path: `/api/bots/${bot.User.id}/stats`,```
capital U on user
I have that
Capitals on ID probably
ya might wanna do User => user
again thats not the problem
It cant read id
has nothing to do with capital letters
is your d.js called bot or maybe client
it has everything to do with capital letters
Oh yeah?
What should be capital and what shouldnt?
non capital u still the error
capital u still the error
capital id with capital u error
capital id with small u error
I have tried everything
That has to do with capital
Im going to sleep
too tired for this shit
cya tomorrow
path: `/api/bots/${bot.user.id}/stats`,
``` @quiet bobcat
const api = new dbl({
token: "not-telling-you"
id: "365689417052192799"
})
api.postStats("Your bot's server count, MUST be a number, not a string", (err, res) => {
if(err) {
console.error(err)
} else {
console.log(res)
}
})
"Your bot's server count, MUST be a number, not a string" isnt a valid guild count
^^^
client.guilds.size?
sure
Yes
make sure that actually exists
and you are running it when the bot is ready not when the client is constructed
i did just say that
k
but you should also do it when your guild count changes
Real answer, learn a coding language like Python or Javascript (or C# if you hate yourself) and learn the respective library
Yea but this server is English so lets keep it that way ๐
np
but just go to discordbots.org and click the Add Bot button
Add your bot
And wait a few days
I hate myself
(Just be sure that your bot doesn't annoy people when it is in this server, like mentioning a lot of people or welcome messages in #general or DM etc. etc.)
same
its a very powerful language
its great, I love it
๐
I was watching a YouTube tutorial and the difficulty curve really bored me
especially net core
I haven't done anything in c# in so long... i should really get back to it
So I stopped until I had to modify Rhinoceros's music bot and got into Python
And I just fell in love
best way to learn c# imho
I learned js by making discord bots
swap js with python for me
and my more advanced c# that I know is from making a bot
I prefer js to python anyday, but I've grown up on C style syntax
But everytime I develop new features or fix bugs I learn new stuff which I like
but I need to learn python because I'm doing machine learning now
Python probably won't be that hard if you come from C#
I need to be typing less, I hurt my wrist
what pisses me off is that now I have to add error feedback to my bot before it gets accepted, and I specifially didn't want it to be spammy

tbh idk why I'm still trying kek
Wait, Discord Best Bot practices recommend you handle errors silently
of course they do, because I followed them
but clearly the people reviewing bots here don't care
wat
It's literally a point on the "Best ways to get certified on DBL"
clearly Arraying didn't get that memo
like if they spent more than 4 seconds mindlessly spamming commands and actually tried using it, who knows, it might actually work
but in two applications they failed both times to even get the bot to work
They accepted mine and my setup is pretty complicated
even though each command is fully documented

maybe I'll add a "use this if you're a discord bots list reviewer" command that walks them through it
Well I'm working on making setup easier for my bot since a lot of people have config issues
Hey, uh, guys?
hello yes
I have a question
It seems my permission checking code has malfunctioned
So my ban and kick commands can be used by anyone
Which is very very bad
ok
show code
Okay
Permissionhas(msg) {
if(!msg.guild) return this.client.isOwner(msg.author);
return msg.member.Permissionshas('ADMINISTRATOR');
}```
are you sure it's running the code
๐ค
That might be the problem
Aw sheet they deprecated it
Why do they always make everything more complicated
Wait
I think i might be able to do somethign with .missing
*something
@earnest phoenix It's called .hasPermission
do you even camelCase
No
Its not
Yes
It got deprecated
It is
d.js?
And doesnt work anymore
Yes
it is definetly still a thing
I can confirm
working fine for me
latest version
um
wtf
why
ยฏ_(ใ)_/ยฏ
Idfk
OH
Wow you need to use .has now
Instead of .hasPermissions
Thats so stupid
Permissionhas(msg) {
if(!msg.guild) return this.client.isOwner(msg.author);
return msg.member.has('ADMINISTRATOR');
Im pretty sure this would work
"Permissionshas" is the function
So thats alright
I changed the permissionshas to .has
Now it should, in theory, be working
Okay wait wait
Ah ha!
I think I know how to create a permissions check system
Permissions(msg) {
if message.member.has('ADMINISTRATOR') return this.client.isOwner(message.author)
}else{ this.client.reply('You are not an admin, silly!') }
Did I place my {} right?
you were looking at Permissions.hasPermission, not GuildMember.hasPermission
Yes
Wait ma minute
*a
This code gives admin to the person who says it
It has to "else" statement
*no
How df
Okay I fixed it
But nwo my bot isnt saying im the owner
*now
I set my user ID
member.has is not a thing 
Omfg I am
Hold on
Permissionshas(msg) {
if(!msg.guild) return this.client.isOwner(msg.author);
return msg.member.hasPermissions('ADMINISTRATOR');
}
there ya go!
๐
Bruh
it's hasPermission
not Permissions
Permissionshas ๐
your isOwner method is probably fucked then ๐คท
๐คฆ
Endmysuffering
Okay, so
const Commando = require('discord.js-commando');
const client = new Commando.Client({
owner: '296837294655143937'
});
EW
commando
Yes
Know what stfu lol
Its useful
According to the documentation, it should be working
Permissionshas(msg) {
if(!msg.guild) return this.client.isOwner(msg.author);
return msg.member.hasPermission('ADMINISTRATOR');
}
This should work, yes?
idk try it
Nope
Non-admins can still use it
Im so confused
WAIT
Why oh why does this code MAKE THE PERSON AN ADMIN
๐คฆ
Wait wait wait
No thats .has
This only checks permissions

Aaaaa
How do I make it so if the value is true, it moves to the code
return?
Nobody is responding
๐
return this.client.isOwner(msg.author);
Well
solution: don't use commando
If I dont use commando
Then all of my bot commands
That I have worked on
Are null and void
Because they use the register groups command
They also use its listing service
For the help comnmand
*command
So basically not using commando would be asking me to start over
Im attempting to download sqlite
Done
Aaaaaaaaaaaaaaaaaaaa
Now sqlite isnt working
Have you heard of our lord and saviour RethinkDB
Redoing everything is natural
WHAT
;-;
Okay know what yeah
Im gonna re-do my entire coding base
Everything is messed up
Im keeping my old bot folder though
Just in case
Ah, a fresh start
Idk how I would even code without commando
I re-installed node
Re-installing discord.js
Done
var bot = new Discord.Client
Would this be good for the start?
Oh
const and let are the future
Alright, I set up a basic starting mechanism from the docs
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
if (message.content === 'ping') {
message.reply('pong');
}
});
I added the login part, I just didnt want you seeing the token
Lmao
Gosh Idk how I would even code commands without commando
๐
I learned how to use just commando, not the root d.js
ah
?
nothing
Okay
At first I was just thinking you were looking at Commando's code for reference
Then I realized that wasn't the case
Nope
Yep
Im gonna copy some of my old code
From my bot
Done
Wait
How do you even make commands in d.js
๐ค
oh god
Yup
Thx
no problem
@earnest phoenix for your php uploader, am I supposed to leave this or change something? https://i.imgur.com/5hwd4vB.png
leave it
You should also change it to any other Directory if you're using another directory that isn't the DocumentRoot
aka any subdirectory
change after the slash for the dir?
@earnest phoenix ^
$config["host"] = "http://" . $_SERVER['HTTP_HOST'] . "/enter directory here" . "/even deeper dir here" . "/";
ok
@earnest phoenix what are you supposed to do to make it not return the contents of the php file again?
wat
Can somone help me? I'm trying to make it so it shows how many servers the bot is in but I get this error ``` path: /api/bots/${bot.user.id}/stats,
^
TypeError: Cannot read property 'id' of null```
This is the entire code ```Javascript
const https = require('https');
const postData = JSON.stringify({
server_count: bot.guilds.size
});
const options = {
hostname: 'https://discordbots.org',
path: /api/bots/${bot.user.id}/stats,
method: 'POST',
headers: {
'User-Agent': 'DiscordBot (https://moustacheminer.com/) Discord Guild Counter',
'Content-Type': 'application/json',
'Content-Length': postData.length,
Authorization: 'X'
}
};
@quiet bobcat That is because there is no user property within bot
so you're trying to get id property of undefined
which u cant do
Thaths why I get that error then
Yes
It fixed it
But now I get this error { Error: getaddrinfo ENOTFOUND https://discordbots.org https://discordbots.org:443 at errnoException (dns.js:53:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:95:26) code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'https://discordbots.org', host: 'https://discordbots.org', port: 443 }
Lol
lol
It's all Tonkku's fault
Alright
tonkku!!!!!!!!!!!!!!!1
@bitter sundial reeeeeeeeeee
I just want it to desplay how many servers my bot is in ๐ฆ
ENOTFOUND is not us lol
What is it then?
are you getting just the frontpage?
Im trying to fix so my bot uses your api to desplay guilds and such
what path
To what?
path to api
path: `/api/bots/${bot.id}/stats`,
pls
DNS servers dont block lookups
It's him
prob on shitty dns servers or something
lul
sure why not
is anyone else having a problem with the api
Only me I think
Really?
ok
@everyone Who is willing to teach me how to code bots? Dm me if yes.
@everyone GTG to sleep.
did he just
lul
!help
this is sad
Wtf
Yeah
We've long past the point of being able to distinguish a real user and a troll
haha
Idk why people think that others want to help then learn how to code without anything in return
I mean fix one command? Sure.
But learn how to code it self wtf
Even if you wrote a guide to programming through discord bots they still would just copy and learn nothing
Yeah most likely
In #312614469819826177 the first one, it links to discordbots.org/api/bots/stats but that isnt found
What should I change it to?
?
Hi, welcome to DBL
Hi
First you need to login over at http://discordbots.org/
You can login with Discord it's a simple click of a button
From there you'll get redirected back to the main page of DBL
why ur name green
No problem :]
Are you running it off your local machine?
And when it was working, was that machine a VPS?
Local and no vpn
D.js?
ye
Well from my experience with D.js.
I couldn't get Voice to work with windows at all
It worked for me on a linux but that's it
I got it to work
Do what you did before ๐
I know that Node and other packages sometimes don't fully update using just NPM
You might need to uh, google that one, sorry.
It's ok thanks for the help
No worries
@quiet bobcat /api/bots/stats only works when POSTing
Ok, but it cant post because the bot cant connect
Uhm.... Uhmmm..... uhhmmm.. node index 'node' is not recognized as an internal or external command, operable program or batch file.
what
the
hell
maybe you should add node then
I have node.js
^ looks like you didn't add it to path
certain versions are also listed under nodejs you can give that a try if you want
I'll download the new nodejs
First ffmpeg wasnt working and now node doesn't work... Good day for me ๐
Yay, everything works ๐
How do I make a command log errors?
try {
// Running your command
} catch (e) {
console.log(`o shit ${e.message}`);
}
You've got to stop asking for everything and learn yourself
hello
hello
Does anyone know how to make a bot online if so message me plz
How do I edit a message my bot sends through my bot?
You could have easily found that out by reading docs
You are using js right?
https://discord.js.org/#/docs/main/stable/class/Message You can read im not gonna spoon feed you its right there
Im already on there
So did you find it 
find what
message.edit doesent work for me
not for me either
it sends me an error saying that the bot cannot edit another uusers message
I get nothing :/
hm
thonk

Moose does work 
im checking if my bot is online or not thank you very much
just needed to view profile
I keep getting this error: TypeError: message.edit is not a function
This is the code for it: javascript message.channel.send(":rage:").then(message => setTimeout(() => {message.edit(":angry:")}, 1000)).then(message => setTimeout(() => {message.edit(":slight_frown:")}, 1000)).then(message => setTimeout(() => {message.edit(":neutral_face:")}, 1000)).then(message => setTimeout(() => {message.edit(":smiley:")}, 1000))
lmao
@quiet bobcat you need to change message => to something other than message, like msg =>
and then all the message.edit to msg.edit
Needs more .thens
Are you sure @tawny lava
sigh do you know how .then() works?
Not really
Well, look for it, because attaching a .then() to another .then()
Idk how my bot even got approved
It is not what you are looking for
Ok
Neither do i, neither do i

Anyhow, look for it and you will understand what you need to do to accomplish what you need
Alright
could someone help translating ms (miliseconds) into a Day - Hour - Minute
discord.js btw....
@crystal void 1s = 1000ms 1m = 60 000 ms 1h= 3 600 000 ms 1d = 86 400 000 ms
You have the exact values there ^^
-.-
how would I recalculate 8555616419661ms into Days - Hours - Minutes????
I can fix it
but how would my bot do that (in js)?
lol
bot.setNickname({nick: msg.content.replace('Testing',)});
^
ReferenceError: msg is not defined```
and if I use message I get message is not defined
But it works everywhere else
so you can change the nick like that?
try eval-ing it
wait.... does this make sence to you @gaunt dune? js nick: msg.content.replace
bot.on('ready', () => {
bot.setNickname({nick: message.content.replace('Testing',)});
};```
try
bot.on('ready', () => {
//bot.setNickname({nick: message.content.replace('Testing',)});
};
python
import json
import requests
url = 'https://discordbots.org/api/bots/' + str(bot.user.id) + '/stats'
payload = {'server_count': len(bot.guilds)}
headers = {'Authorization': 'secret' }
requests.post(url, data=json.dumps(payload), headers=headers)```
This correct?
why don't you just do bot.setNickname('Tesing');?
@autumn nova sry... we are js... ask someone else
idk
yeah even that would work...
bot.setNickname({nick: "testing"})
^
TypeError: bot.setNickname is not a function```
.-.
maybe you could find the answer there
yup, lol
๐คฆ
cause you're usseing it in bot.ready and not bot.message
where it gives you the message's contents
but
there's no message where you're using it
Ok so bot.on.message?
๐คฆ
๐คฆ
ikr
๐ฆ
bot.on('message', message => {
your thing here
});```
yup ๐
Still message isnt defined
Make it failproof please
Im really bad at coding
Youre kidding me
I fixed it
...
bot.on('message', message => {
if (message.content === 'jo.nick') {
your thing here
}
});```
I forgot to remove the change nick from startup commands ๐คฆ
there you go
finally
or if you want it to happen on a command do te thing that I've just sent
Sorry for taking your time with my stupid questions
And btw I dont think the code you sent would have worked. I use case "command": to make my commands not if()
No thats all ๐
-.-
Dont ask why
u use ur own command handler?
no
but it can disable other users helping you...
I mean.. they don't have your code
put your bot on github or something
Either way I have to go now! Cya and thanks for all the help!
k ๐
Opinions; which is easier to code discord.js or discord.py
Easier to code/understand*
I'm assuming thats why there is alot of discord.js bots
my opinion
i'm the opposite lol
so you're a FILTHY COMMI?
no
so you're NOT the opposite :o
@gritty dirge Is going to be down for next 15-30 minutes due to maintnance! Adding a function to play music!
joy
my bot is down an hour every other hour
and I have MANUALLY restart it
(โฏยฐโกยฐ๏ผโฏ๏ธต โปโโป
is this your bot?
Drugs are bad m'kay
Nah
How to edit bot messages after the bot send one? message.edit doesent work for me...
channel for chatting about bot development
wrong channel whoops my bad
it's called async and it's a nightmare :)
How to edit messages sent by a bot?
Code:
case "test":
message.channel.send("mk ok bud");
message.channel.edit("k")
break;```
message.edit won't work.
@lethal sun is that Aeirety's thing?
@lethal sun are you using C# .net?
also message is refering to the user's message
so message.edit would edit their message
discord.js...
and @crystal void yes case is easier for me
and the code isnt a big of a mess when u use case
for commands
ok
whatever... no judging
@lethal sun
var m = message.cha...
m.edit("edited");
try that
if that doesn't work, you will have to have async enabled
1 sec copy&pasting my bot's code
bot.on('message', async message => {
// Code
have that at the beggining to enable async
then
async var m = message.cha...
m.edit("edited");
try that boios
@gritty dirge is going to be down for 15-30 more minutes due to maintnance! Adding a function to play music!
owo
`
async var m = message.channel
^^^
SyntaxError: Unexpected token var`
@gaunt dune

thonk
sure you have m.edit(...);?
yes
yes
that's not very nice
const m = await message.channel.send("m ok bud");
that was not my simplified ping command
xD
lol
ikr
lol
i never actually knew how to make bot to react with a server emoji
your bot can type server emojies tho
"type"
AND MY BOT CRASHED AGAIN
WHUP DE DOO
okey it's back

crashes are nice
so far no crashes on my bot, but I'm pretty sure I've jinxed myself now
Ikr
@lethal sun That is not right
it should be "const m = message.channel.send("mk ok bud")"
actually, put the word await before message and make sure the function is async
(node:18268) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property '364451125438709811' of undefined
(node:18268) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
How do I get a timed message, like a daily reminder? I already have the time by var d = new Date();
use a setInterval or a database
haaaaaaaalp I'm so messed up... so desperate
for (let i = 0; i < rows.length; i++) {
let string1 = `${rows[i].rank}. `;
let string2 = `Level: ${rows[i].level} (${rows[i].xp}/${rows[i].xp_required} XP)`;
bot.fetchUser(rows[i].user_id).then((user) => {
string1.concat(`${user.username} (`);
});
bot.fetchUser(rows[i].user_id).then((user) => {
string1.concat(`${user.tag})`);
});
embed.addField(string1, string2);
}
I have no idea how to use promises
basically what I'm trying to do is
for (let i = 0; i < rows.length; i++) embed.addField(`${rows[i].rank}. ${bot.users.get(rows[i].user_id).username} (${bot.users.get(rows[i].user_id).tag})`, `Level: ${rows[i].level} (${rows[i].xp}/${rows[i].xp_required} XP)`);
but using that will make my bot crash if it meets an user ID that is not in that server...
tried to change from bot.users.get(rows[i].user_id).username to the client#fetchuser thing
interval?
How does an interval help
My status reset for my bot is set to an interval

that's irellevant to my needs though
Oh
exactly how would an interval solve this
You have the daily reminding mechanism?
are you trolling? ๐
No
Omg, okay so is your code messed up, or your time interval
I can only help with the time interval
a time interval for what
I don't need help with that, thank you
I have trouble with this because I don't have experience with promises in js and I'm trying to make use of them to add stuff to a RichEmbed
Oh
Wait hold on bruh
Ill give you a link
Learrrrnnnn
I already had that page open for the past one or two hours
rofl
xD
@trim steppe BOI
:/
Wait
ok
Whos a good programmer you know
Thats not busy
err
throw err;
well most people i know are in the other bot list
because i used to spend the most time there
just ask now
i guess
i can take it
:/
basically I suck at promises and I need them to add stuff to a RichEmbed
tried to change from bot.users.get(rows[i].user_id).username to the client#fetchuser thing
๐ค
but I have no idea how to return the username through that... it's using promises
client.fetchUser('6969696969').then((user) => {
console.log(user.username);
});
hmm ok I guess that should work
but
how do I add that to a string in a addField in a rich embed?
I mean
user.username is a string
client.fetchUser('376147022660632587').then((user) => {
console.log(user.username + ' is really dumb.');
});
unless you want to use templates
for (let i = 0; i < rows.length; i++) {
let string1 = `${rows[i].rank}. `;
let string2 = `Level: ${rows[i].level} (${rows[i].xp}/${rows[i].xp_required} XP)`;
bot.fetchUser(rows[i].user_id).then((user) => {
string1.concat(`${user.username} (`);
});
bot.fetchUser(rows[i].user_id).then((user) => {
string1.concat(`${user.tag})`);
});
embed.addField(string1, string2);
}
I have tried this and it doesn't work. what am I doing wrong?
client.fetchUser('376147022660632587').then((user) => {
console.log(`${user.username} is really dumb.`);
});
string.concat?
string.concat returns a string
yea
.:face
I always use +=
๐คฆ
so i was surprised
https://send-me-some.discordmail.com/1509758230.png
@earnest phoenix

why? :-<
because fetchuser is async?
oh
well it's worth a shot
all of the addfield and sending functions need to be put in the callback for the promise or it'll be run before the promise is resolved
I mean not even an username or w/e
meh
@earnest phoenix

