#development
1 messages ยท Page 905 of 1
best would be if I could get them in an array
since I want my anti nsfw bot to also be able to scan emojis
I did searched it online but didn't find anything which fits my situation
thats a very interesting question, i'd go and remove all text (non emojis) and add each emoji to an array as a object or sth, and get the url, and scan it
that's what i would do 
yeah but how do I do that
i have no idea
split at < and >
and afterwards join all text between < and >
and get rid of each other?
though the problem of having a loose > in your text would exist
I mean I did find a node module for getting emojis as an array but that one was made 9 months ago
mm yeah
hi
I could try forking the code out of the module I found
let a = guild.tags.find((e) => message.content === e);
if(!!a.name) {
message.channel.createMessage(a.response)
}
``` why am i getting `can't read propery of 'name' of undefined`?
What is that double !!
Im currently using glitch to host the bot 24/7. I had no idea how to do it so I looked up. I did what they said and it doesn't work. I'm using uptime robot.
uptime robot is for monitoring ur services, not hosting
Oh, because I looked in the forums.
I have used this to minus the money
from a person's account
but i think fetch won't work
please tell what should I do
the db library u r using
Yes
u asked us to ask u: tell u what to do
i say ask u: what db library are you using - not a yes/no question
How can I host the bot 24/7 in glitch then?
Lost said its for monitoring, not hosting
then you used it wrong? idk
I have codes to keep bot 12 hrs on9
I did put the correct the application link in the monitor
You may need a web server on the glitch projecy
Used to do it before and thats how I got it working
How do I get the web server?
This has one
Oh right, idk then
someone hosted a python bot on heroku
glitch is made for web services, not for websockets, like discord uses
well, you need a credit card
to be able to provide their service for free, glitch automatically puts inactive services to sleep mode, and awakes them when they receive a request
so what you need to do is to regularly make a request to your glitch project to prevent it from going to sleep mode
They also limited the amount of projects you can keep online 247 to 20
They also released a paid plan but its a rip off at that point
glitch just has a bad uptime
For what you get its better to buy a pi
i would say a cheap vps
I guess I should stick with heroku then xd
none of those free services are made for bots, so you're gonna have a hard time on either one
never heard of a stable free bot hosting service either haha
I mean, I am using heroku to host the bot but I want to switch to glitch. but eh
why?
its basically switching from one bad thing to another bad thing
if you're gonna go through the effort of switching, at least switch it to something good
its my only choice to host it 24/7
Can't you pay for a vps or self host it
a vps would be ideal
probably*
for now just stick with heroku since they have a better uptime and move to a vps when you can
Alright,
Also
I switched my codes to cogs in python, so when I imported all the files, added the reuirements.txt, procfile, etc, I tried to deploy but it says that its compatible
im using github by the way
im trying to run it on heroku
you mean "not compatible"?
try removing the python buildpack from heroku and redeploy
so I forked and fixed and modified the discordjs-getemojis module and now I can get the ids from the emojis from a message but how can I check if the emoji is animated or not (without the emoji being cached or without the bot being in the server of the emojis)
okay
emoji.animated?
ah
dont think you can get any data just from an id
and since there is a chance the bot isn't in the server of the emojis thats also a problem
you can try fetching the .gif version of the emoji and if the status code is not OK, grab the .png version instead
however the message content will include <a:name:id> if its animated wont it
do I just loop through the formats untill I get data sent back or what
just gif
it still says that it's not compatible.
@marble juniper is checking if its animated all you need?
wouldnt the message content include <a:name:id> if its animated
yeah but idk how this module works since I just forked it
thats it
lol
Idk what the hell the regex does or anything
lmao
if a .gitignore file is in a subfolder it will only apply to that subfolder right?
yes
ig
and the child folders ig
jesus christ lmao
guess I will just try to loop through the formats
i guess it parses unicode emojis?
yeah
pretty much any emoji
the module didn't work since it didn't have .cache.get
thats the only thing I needed to fix
it does only apply in the subfolder
why don't you use that instead (cache.get)
I did
but
ah forget it
I will loop through the formats with get requests
untill I get a result
that would be my solution
i think png format exists for all emojis so you only need to check for gif
i might be wrong
well after I changed an emoji url of a non animated one to gif it gave me a 415
so I can check for that status
with axios
lel
yep
that should be the solution
thanks yall for the help
cya
nice. np man cya
does it work if the main code is inside a folder along with the reuirements.txt, procfile,etc and then deploy?
go ask in thier support server
so it has to be outside the folder?
so try putting the procfile in the root dir
Oh alright
I accidentally made an folder for the first layer
How can I remove the folder but keep the codes, etc?
I'm on 32 bit though
Github desktop is on 64-bit though
hmm, I could make a new repo
how many files are there in that folder?
yeah probably make a new repo
why are you using github tho
GitHub is good
@chrome field is it changing in your Developer Portal? or can you not use it anymore once it changed?
(expired token) NjY3ODIxMTQ0NTY4NjI3MjIw.Xq6isA.geGvNt9Ko8B6WstABS4dgREKOG8 because this part changes every time you reload your page
well atleast for me
hopefully the token was regenerated
it's an old one from a deleted application
I don't do anything but it changes on its own, I don't even need to refresh the page
I can run if I am fast enough, but it is automatically renewed when not fast
gitlab is better
I notified Discord support team, but they haven't returned for 2 days
i never had any issues with the token regenerating itself
no System Notifications either?
no System Notifications either?
@earnest phoenix no
they're saying that the token gets regenerated randomly, making the old one invalid
My bot token is constantly changing automatically and if I can't be fast enough when I reboot my old code, I need to reboot my codes
@chrome field Maybe you could just make a test code to check if that's maybe your codes issue or something, just a simple command returning your username
does the entire token change, or only a part of it? because its normal for a part of it to change
@chrome field Maybe you could just make a test code to check if that's maybe your codes issue or something, just a simple command returning your username
@earnest phoenix Ok i can try
does the entire token change, or only a part of it? because its normal for a part of it to change
@quartz kindle It refreshes even though I don't press the rebuild button
There is no problem in the way the token changes, but there is a problem in its constant change.
Okay, so it did deploy and it worked.
But
the bot didn't went online
I dont see any errors on the logs as well.
@chrome field what rebuild button? you mean the regenerate button?
@chrome field what rebuild button? you mean the regenerate button?
@quartz kindle yes
if only a part of it changes, its not a problem
its the normal behavior, and the changes dont invalidate older tokens
if only a part of it changes, its not a problem
@quartz kindle there is no problem but the problem is that it changes every second even though I do nothing
but if the bot works, its not a problem
but if the bot works, its not a problem
@quartz kindle bot does not work because the token is constantly changing because the token is invalid when the bot will run
hence why i asked, does the entire token change? or only a part of it?
only part of it is changing
I'm currently trying to run it with simple codes
if you dont explicitly regenerate the token, it will always work no matter how much it appears to change
because the key component is not changing, only the time component is
Regarding my XP bot. As you know (tim) i changed the database engine from memory to innodb yesterday and cpu shows better performance.
However, you said i should cache stuff that gets accessed frequently. so i wonder if maybe it makes sense to let only the guild table in memory, because it is accessed with every message to check for the command prefix.
okey, thank you for helping @quartz kindle
@viral spade i would not rely on mysql memory
ok, but will i need to cache the row, where the prefix is in sometime, right?
or wont this be a problem for the disk for a long time?
MEMORY performance is constrained by contention resulting from single-thread execution and table lock overhead when processing updates. This limits scalability when load increases, particularly for statement mixes that include writes.
Despite the in-memory processing for MEMORY tables, they are not necessarily faster than InnoDB tables on a busy server, for general-purpose queries, or under a read/write workload. In particular, the table locking involved with performing updates can slow down concurrent usage of MEMORY tables from multiple sessions.
oh sounds about the exact wrong usecase for an xp bot ๐
yup
prefix should be cached in the bot itself, like in the guild object for example
ohh, i can safely add properties to the client object?
what i do is this:
- check guild prefix
- if guild prefix doesnt exist, check database for guild prefix
- if database exists, put prefix in guild, if doesnt exist in databse, put default prefix in guild
- on prefix change, update both guild and database
yes as long as you dont accidentally overwrite something that already exists
oh that is really nice
i thought i better not temper with the discord js object
and what is the amount of servers where someone should really implement the prefix check that way?
the safest way is to create a custom namespace in your objects
for example, i use AppData
oh that sounds also nice
namespace you simply mean like an extra property? not like in c?
yes, a single property to contain everything that is specific to your bot, and not part of discord.js
nice, i willdo it that way. So at what servercount would not implementing it this way bite me in the ass?
approx.
you mean as compared to querying your db on every single message?
yes
querying the db on every single message will be bad since the very beginning, and exponentially get worse as your bot grows lmao
hmmm. thing is, even with the prefix cached, i will need to call the database for almost every message anyways, because a message is either a command, or has to be added to stats (most of the messages).
So i guess i have to implement the cache for stats too (periodical flushing of groups), or i wont see much difference?
i would cache everything that is checked on every single message, including non-commands
you can leave db queries for actual commands
ok this would basically means, cache every setting (guild,guildmember,role,channels) and let all my like 30 setters operate on both, cache and db. And use only the cache when working off an event?
yes
and only query the db when the event passes whatever it condition it needs to pass
for example once you confirm that a message starts with the correct prefix and contains a valid command
anyone know a library that can convert a string like "europe/berlin" to a number equal to it's current gmt ? so it would account for daylight saving hours
so npm i moment-timezone
Yes
know a website you can enter and it displays the respective string you would have to input?
that would work, but it's something i need the end user to provide
would it be possible to make a site maybe, that a user can click and upon visiting the site reveal their timezone indirectly through the http request or something like that
Okay this is very comprehensive for me for settings tables (guild, guildchannel, guildrole, guildmember).
But with the stats tables (textmessage, voiceminute,vote,bonus) i am not sure.
First would you do it user.AppData.textmessages [channel,count]
or
channel.AppData.textmessages [user,count]
?
and then how would you flush it? A periodical infinite loop over all users/channels. Lets say users.
Then rotate over the users to calculate their possible levelups/totalScore and add it to the cache. Then rotate again over all users to take the rows for all/multiple users and add them in one transaction.
like this?
id go with user
are scores global per user or guild specific per user?
so i would do like this
- on message check if member object has scores
- if no scores, retrieve scores from database and add them to member object
- do whatever updates you need to do to the member object
- push a copy of the update to the database
Ok i see. Thats what i am already doing basically with the (former in-memory) database, to a remote database on another machine.
When a row in any table does not change for 1 hour, but maximum after 4 hours (if it has been changed), it will get pushed to my persisent remote database.
I thought using an in-memory db is like using "in-program variables" as cache.
So basically i could delete the "local" database completely, transfer my whole "local" database into cache/"program-variables" and update to the remote database from within the cache.
depends, if you're not gonna push the cache to anywhere for hours, you could lose a lot of data on a crash/restart
thats okay, if i get a lot of perfromance for it
settings tables are updated more frequent
where is the documentation to the moment-timezone lib?
yo should i make my cluster master open like a utility http server rather then using purely worker message posting? idk if it'd be faster or not but feels like cuz atm it needs to send an event and then wait for another event back with the same ID and while that'd still happen on fetching data it wouldn't happen between requester and manager if it was http
if i cache within the shards client object ,for example the guild, but also other tables, would you rather cache everything (like 50 rows with different settings) or really only the information needed like prefix and totalScore to check/select, so only "rare code" causes db queries.
I wonder should i really add specific stuff to the cache and let the rest be as is, or transfer like everything into the cache, before it lands on the (non-container) backup db., cutting out the db in between.
@slim heart i would do uttility
otherwise its a real pain controlling your clusters globally
how could i make the moment-timezone lib communicate with Date()? i'd like to calculate the utc offset or gmt of a given timezone ie convert "europe/oslo" to +2
like the ability to get /guilds/id rather than sending a GUILD_FETCH and waiting for a GUILD_FETCHED back
current is what i do and works fine but if http is faster than i'm all for it
i have all my clusters setup so they all host a small http server
and the master webserver allows me to control restarts turn shard on and off etc...
so the webserver tells each cluster what it is and what todo
i don't think that's good practice tho
http servers on all clusters is bad
but idk abt http servers on only the master
they only act as clients
so the server can send a receive data to and from the clusters
that's what the worker thread messages are for
i prefer not to have a file in control of it
deploying via k8s
scaling with that
each server is designated by the k8s router
tho idk how well js does sub process managing
m websockets would be the best solution really
yh
for me its easy enough just to have a small http server that is like 20 lines that just lets the containers talk to and from the other systems
tho all contained in VMs
im looking into how to orchestrate something like that too
any of you tried out unix sockets or tcp messaging?
I personally would say trying to scaling anything without containing it with docker or somthing is a bad idea
wayyy to easy to get dameons
what i do with worker thread messaging will be the same as what is done with websockets if and when i scale across multiple machines
i just send message events with an e and d, e being event name and d being data payload
how r u deploying it
so it creates all the workers and if it were websocket wait for all of them to connect, at which point along with worker data would send the id of each cluster then the master sends SPAWN payloads with an array of shards to spawn and shard count etc, and when all the shards on the cluster ready up it sends READY back to master which then SPAWNs the next cluster
ah
I use kubernetes stateful sets
so each scalled container has a incremented id
which the worker can get just from getting it's system name
i'd rather not rely on a platform like that ig
why not
if i were doing websocket i'd just tell the cluster which id it is
its considerably better than doing it with a file to control
turkeyyyyyyyy
cuz if i wanna change from kubernetes then yeet
then thats easy?
im thinking about doing the opposite, instead of a master sending spawn payloads, have the shard request permission to connect, and the master only controls rate limits and allows or denies
k8s just uses docker containers which are good practice for deployment anyway
but overall it only takes one process to not close properly and then you start getting issues
which is where things like k8s are good
well tim that would be better for largely scaled bots possibly, don't to very tiny increments i think. but the thing is you want them to spawn within identifyable times since it's heavily ratelimited
not to mention the ability to dynamically scale and increase clusters / decrease them just by doing --scale xyz
sort of the point of a master is to control not limit but it'd work ywah
and setting limits to how much each cluster can use to stop one hogging or causing issues
i have another idea in mind
that plays well with this method
hot-swappable/resumable shard restarts
cf8 i just don't like the idea to locking everything i do to having to be on a platform (kubernetes). if i wanted to switch now there's a bunch of thing i'll have to reimplement which i could just do inside of the netes and not use a proprietary feature if that makes sense
also that'd be interesting yeah
be able to move shards off of specific clusters and then do whatever with it
another reason i am sort of liking the idea of the http server is cuz atm i host the dashboard on cluster 0 which obviously isn't great but in order to move it off i'd have to outfit all the events to ignore it and yada itd be annoying. so an http server wouldn't require the worker to be a cluster thread n stuff
Sounds like bad fore thought to me xD
Would it be too much to cache my whole statistics data within the clients user objects?
user.AppData.stats.textmessage = [{guildid,channelid, values,..},{guildid,channelid, values,..},..]
user.AppData.stats.voiceminute= [..]
...
So should i only pick specific values to cache from each table? Like totalScore, prefix, ..
if you put stats in the Member object, then you dont need to have the guild id on every item
less memory waste
right, but would it be too much then?
and yes, i would keep only the hot values in the cache, values that are accessed on every single message/event
but anyways ig my question still stands is http faster or the same or slower then worker thread message exchange by any noticeable amount?
wait utc offsets that isn't just whole hours but also minutes is a thing?
+08:45
yes, i would keep only the hot values in the cache, values that are accessed on every single message/event
So for statistics tables, where basically every message causes an update event, would caching 30 seconds+bundle in 1 transaction reduce the workload only a bit or drastically, compared to make a write in the db for every message?
@slim heart in theory, http is much slower, but in the real world, the difference shouldnt be more than a few miliseconds
Because i mean the same amount of data has to be written, only the overhead is less
alright, sounds good
but before jumping into http, i would look into unix sockets if same machine, or tcp if networking
@viral spade the amount of data written has a much lower impact than the amount of individual writes needed
think about downloading a 5mb file compared to downloading 50 100kb files
aren't unix sockets just ipc?
oh, interesting. Thank you!
yeah, node's ipc module has all of them
why would i use it?
tcp is faster than http
is it faster than the worker.postMessage?
since worker threads share memory, im not sure if their IPC uses sockets or something else, but most probably they are the fastest
but generally sockets are the fastest way of communicating between processes in the same machine
right
eventually when i move because of memory usage i'll end up doing that probably
gotta long way to go though lol
another option i have been thinking about, would be using a database as some sort of master process, but that will most likely be slower
for example, keeping all caching in a redis db, so you have a unified cache throughout all shards
i mean ik like redial
fuck
redis* but u already said it lol
i'm pretty redis can do a pubsub sort of thing
so communication and cache
yes it can
im trying to write my lib with all that in mind
never really thought i'd need it but might be cool
hopefully it gets somewhere
yeye
moment-timezone seems to only give gmt in whole hours, but when i google i come across a bunch of countries that has their gmt as hours and minutes
how are you getting the offset?
moment.tz(tz)
wait is that a different norfolk
oh wait this one isn't a whole hour
i use it like this moment.tz.zone(timezone).utcOffset(date)
but my use case is different
oh i use it like
moment.tz(tz).toString.splice(-5)
if (message.channel.id == "702161547421810824") {
if (message.content.startsWith("+hey")) {
message.delete();
message.channel.send("All Works!");
} else {
message.channel.send("Delete does not work!")
message.delete();
}
}
Why does he not go in the else-block?
context?
well if the message doesn't start with +hey, it says "Delete does not work!"
that's what your code does
Tim if you want you can look for a <5$ key on g2a and i buy it for you and send you the key as a little thanks
there isnt anything im interested in on g2a at the moment, but thanks :3
should i use mongodb or redis for longer cooldowns (hours to day)
(im using mongodb as a general database anyways)
then stick with it
aight
i tried fetching channels from the quick.db
let fetched = await message.guild.channels.forEach(channel => attachmentchannels.fetch(`${message.guild.id}.${channel.id}`))```
and its returning undefined when i console log it
@earnest phoenix If I write a message with kek it will come nothing
let fetched = await message.guild.channels.forEach(channel => attachmentchannels.fetch(`${message.guild.id}.${channel.id}`))```
anyone knows what the problem is ?
@earnest phoenix then dont console log it
bruh
200iq
if you dont have a real answer then dont answer
How do u saving data?
oh..
we need an error and what you're actually trying to do
im using quick.db to store the data
so what is
you can use something like map
channels.map(x=>fetch(x stuff))
that'll give you an array of promises
which you can Promise.all
How to get question id's and correct option id's in python any one can explain
now its sending
1,1
(2 channels)
i need to get the name tho
@slim heart
i told you what you need to do idk what else you're trying to do so
let fetched = await message.guild.channels.map(channel => attachmentchannels.fetch(`${message.guild.id}.${channel.id}`))```
its returning 1,1
(which are the 2 channels)
but i need the name
Bro jpb you know how to
Do
then just .name
it doesnt seem to be working
what're you doing
i tried putting .name after `)
Bro jpb you know how to
@earnest phoenix no you're entire question is extremely vague
no you need to map the response
replace id with name
but im fetching the id
You now Python dict
no you need to map the response
@slim heart how to
i dont use map so much
@earnest phoenix access the key data
let fetched = await message.guild.channels.map(channel => attachmentchannels.fetch(`${message.guild.id}.${channel.id}`))```
this is the current code
im so confused lmao
Bro can example bro
and since that seems to be a list that's the value... ['data'][0] and then access the key question_id from the returned data
Accessing dict keys in Python is basic language knowledge, though 
You access a dict key like some_dict['my_key_ooo']
shivaco, how can i map this?
let fetched = await message.guild.channels.map(channel => attachmentchannels.fetch(`${message.guild.id}.${channel.id}`))```
this is the current code
im so confused lmao
Why are you assuming I speak JS
what are you trying to do
Well that's my answer to your question :^)
fetch all channels that are in the db
so why do you need map
i tried forEach but i was told i need to use map
forEach returned undefined
Thanks bro shivaco
I'm not sure how to make my code so if you have the role, the code wont run
check for member roles
client.on('message', (message) => {
if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) {
message.delete()
.then(message.channel.send('no invites allowed'))
}
})
i dont use map so much
@earnest phoenix then google it
i tried but i didnt find anything
lies
fr
very
no you're either lying or blind man idk what to tell you but we're not here to give out code
it's literally the first result when you google "map js "
i looked for map response
no Array.map
Found with javascript map
if you can't use google then you can't code
but i looked for map response
not js map
i now did
yeah i didnt
google uses keyword searching, not 23rd century technology that reads your mind
lmaoo
lmao
how the fuck do i display a Set in a string without having it as [object Set]
@mossy vine just stringify it
it should
Guys do you know why it shows (Object, object) in Discord.js?
const playembed = new Discord.MessageEmbed()
.setTitle(`${song.title}`)
.setColor(`RANDOM`)
.setURL(`${song.url}`)
.setDescription(`๐ถ Sta cominciando: **${song.title}**`)
var playingMessage = await queue.textChannel.send(`${playembed}`);```
try await queue.textChannel.send(playembed);
let fetched = await message.guild.channels.array(channel => attachmentchannels.fetch(`${message.guild.id}.${channel.id}`))```
its returning every channel in the server
lmao
k let me try
It doesn't work @pale vessel
Hi, I have a question, how can I do to play a song with a link but then a command to skip that song? xD
make a queue system
I have it
xD
but i don't know how to do to play the link with the command
add it to the queue*
if you made a queue system, you should know how to do that lol
let fetched = await message.guild.channels.array(channel => attachmentchannels.fetch(`${message.guild.id}.${channel.id}`))```
its returning every channel in the server
@quartz kindle not if they copy and pasted it from a guide 
@mossy vine did you solve the set thing
that would mean he didnt make it :^)
It's from my friend
@pale vessel yes by not using a set because i realized its not even what i need
xd
client.on('message', (message) => {
if (!message.member.roles.cache.some(role => role.name === 'Allowed')) return;
if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) {
message.delete()
message.channel.send('invite links not allowed')
}
});
im not sure where to put the role checking so if role 'Allowed' then don't delete their message and if they dont have the role then delete their message
how did you try to stringify the set though
doesnt matter as i literally dont need to use a set
@earnest phoenix you're sending the object inside a string, just send the plain object, who told you to string interpolate it?
hello there
i upgraded my bot from node 10 to node 12 and upgraded all packages
i guess there is no bot.guilds.reduce in node 12
what should i use instead?
guilds.cache
did you upgrade to d.js v12?
idk why i assumed you did
All the .send***() methods have been removed in favor of one general .send() method.
finally
wasnt it already deprecated for years anyway?
it was already removed from master all those years it was not stable yet lmao
if its not broken, dont fix it
i have a bot thats also in a very weird state
using discord.js master before the addition of the .cache thing
so its neither v11 nor v12 (well, its v12.0.0-dev)
lmao
hi,
let a = `${guild.tags.find((e) => message.content === e.name)}`;
if (a) {
return message.channel.createMessage(`${a.response}`);
}```
i have this, how can i check for tag being in front of the a? so the syntax would be !tag hi and not !hi which it is atm, anyone got any ideas?
no idea what tags are
@digital ibex simply "a?tag " + a
Am I doing something very stupid here or is this right? .setImage('https://top.gg/api/widget/702935974308741140.png?v=' + (Date.now() >> 0).toString(36))
It's not loading any picture
To load the DBL stats widget into an embed
where are you using a
a is the tag
if (a) {
yes
just like a normal bot
those probably use APIs
axios on js, http on python
const args = message.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase();
if (command === `subtract`) {
const user = message.mentions.members.first();
if (!user) {
message.channel.send("Please mnetion someone");
}
if (!args[1]) {
return message.channel.send(`Please give the amount`);
}
let cdata = db.get(`cdata_${message.author.id}`);
if (cdata === null) cdata = 0;
if (args[1] > cdata) {
return message.channel.send("You do not have enough money");
}
db.subtract(`cdata_$(user.id)`, args[1]);
await message.channel.send("Money subtracted successfully");
}
});```
I am trying to subtract money from a user's acc. but now working
now error
but money is not subtracting
-needdev
DBL is not a place to find developers for jobs. You can try and put a request on Fiverr or Freelancer. Please do not post the request again. Doing so may result in punishment.
got it @slender thistle
oops
Wrong channel
its website admins problem
also try again a bit later
can anyone help me with my code, the permissionsFor isnt working
client.on('message', (message) => {
if (message.member.roles.cache.some(role => role.name === 'Server Administrator')) return;
if (message.channel.permissionsFor(message.guild.me).has("SEND_MESSAGES","MANAGE_MESSAGES", true)) {
if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) {
message.delete().catch()
const embed = new Discord.MessageEmbed()
.setColor(15158332)
.setTitle("Access Denied")
.setDescription("Invite links are not allowed in this server. \n Please make sure you have the `Server Administrator` role then try again.")
message.channel.send(embed).catch()
}
}
});
that's not how includes works
if (message.content.includes('discord.gg/') || message.content.includes('discordapp.com/invite/'))
I fixed it now but the permissionFor isnt work
do you get any errors?
nope
hey
has("SEND_MESSAGES","MANAGE_MESSAGES", true)
bruh
it's has(["SEND_MESSAGES","MANAGE_MESSAGES"], true)
oh
if(!message.member.hasPermission("MANAGE_MESSAGE")) return message.channel.send(You don't have permission);
const userMessage = args.join(" ");
await message.delete()
const botMessage = message.channel.send(userMessage);
botMessage.react('โ
')
ah
wdym
why its dont work ?
also
people think that with just a chunk of code we can guess what the rest of their workflow looks like
it's probably a problem with some other random shit
the bot doesnt react why ?
mine works now its just I don't know what to change this if (message.member.roles.cache.some(role => role.name === 'Server Administrator')) return;
or use promises.
const botMessage = message.channel.send(userMessage).then(msg => msg.react(':white_check_mark:'));
because it sends cannot read property 'roles' of null
instead of using await
in console
bc I don't want to explain how to use async await
@royal portal by fetching from ur bots cache.
hm
if (message.member.roles.cache.some(role => role.name === 'Server Administrator')) return;
add a!
@copper cradle it dont work
with a code block
because it cant read property 'roles' of null
how i made a code block ?
```js
c o d e
```
```js
code here
```
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
if(!message.member.hasPermission("MANAGE_MESSAGE")) return message.channel.send(`You don't have permission`);
const userMessage = args.join(" ");
await message.delete()
const botMessage = message.channel.send(userMessage).then(msg => msg.react(':white_check_mark:'));
};
module.exports.help = {
name: "poll"
}
and please follow the markup
wait
remove const botMessage
bc you don't need that anymore
does it send the message?
do you get any errors in the console
no
change what I told you and show your code
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
if(!message.member.hasPermission("MANAGE_MESSAGE")) return message.channel.send(`You don't have permission`);
const userMessage = args.join(" ");
await message.delete()
message.channel.send(userMessage).then(msg => msg.react(':white_check_mark:'));
};
module.exports.help = {
name: "poll"
}
how come it doesn't react to it
idk
use the actual unicode character
what ?
White check mark is a real character supported
fuck
yeah you can't paste it anymore
idk why they did that
just look up white check mark on google and copy the character
oh you can paste it
add a
!
@pale vessel thats not what i meant
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
if(!message.member.hasPermission("MANAGE_MESSAGE")) return message.channel.send(`You don't have permission`);
const userMessage = args.join(" ");
await message.delete()
message.channel.send(userMessage).then(msg => msg.react('โ
'));
};
module.exports.help = {
name: "poll"
}
ok
like this ?
yes
you didn't tell shit, how am i supposed to know
or else it will delete invites if the user has the role
what flazepe said
the problem is that im not sure on how to replace the message part in if (message.member.roles.cache.some(role => role.name === 'Server Administrator')) return;
oh its work thx !!
because the member didnt send the message
ok tell us if there is any error
cannot read 'roles' of null
console.log(message)
are you sure message is what you think it is
im trying to make it so if you dont have the role 'server administrator' then delete their invite and send the 'access denied' message and if they have the 'server administrator' role then let them send the invite
ok
and now how i put โ with the mark ?
not you sarloux
\ โ
ook no
if i add the ! then people with the role cant send links with discord.gg
only some emoji works
\โ
im trying to make it so people with the role are allowed to send invites
how i put it too ?
and people without are not allowed
you put return
so if they don't have the role, which is false
or oh wait
return means it doesn't do anything
yeah but at the start it has message.
never mind then
and the user didnt send a message
cannot read 'roles' of null
@royal portal Do you check if the message is sent in DMs? messages sent in DMs won't have amemberproperty
client.on('message', (message) => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
if (message.member.roles.cache.some(role => role.name === 'Server Administrator')) return;
if (message.channel.permissionsFor(message.guild.me).has(["SEND_MESSAGES","MANAGE_MESSAGES"], true)) {
if (message.content.includes('discord.gg/'||'discordapp.com/invite/')) {
message.delete().catch()
const embed = new Discord.MessageEmbed()
.setColor(15158332)
.setTitle("Access Denied")
.setDescription("Invite links are not allowed in this server. \n Please make sure you have the `Server Administrator` role then try again.")
message.channel.send(embed).catch()
}
}
});
done
but it still will do the error
randomly
because its before the user sends the message
it might be fixed now
let me check
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
if(!message.member.hasPermission("MANAGE_MESSAGE")) return message.channel.send(`You don't have permission`);
const userMessage = args.join(" ");
await message.delete()
message.channel.send(userMessage).then(msg => msg.react('โ
, \:x:'))
};
module.exports.help = {
name: "poll"
}
fuck
???
oh i can make this
๐คฆโโ๏ธ
hahaha
i know
technically that is only one argument lol
for every emoji you want to add to the message
how ?
@tardy estuary still wrong
yeah lol
you'd do something like this
you'll have to add two reactions to the same message
2 lines of code for that, afaik
msg => {
msg.react('โ
');
// then add more react functions
}
yeah that
now they copy and paste this into a random line in their code
oh
'why is bot not work'
i will try it
lmao
im totally cool with people learning how to code, but yeah its frustrating when they just copy your example without knowing what its doing
but anyway im just gatekeeping lol
okay but how i can do this
what exactly do you want to happen when the user doesn't have the correct permission to do what they are doing?
Lets assume i have two bots on two vps with a persistent database on each. The entries in the databases correspond to guilds in the respective bot.
Now i want to let the bot run on 3 machines and increase the number of shards. From what i understand by the sharding formula, guilds will be reassigned to different shards when increasing the amount of shards.
Is there any way to increase shards and machines without reassigning the guilds to different shards, so each guild stays on the vps where the data is? How is this problem solved usually?
there is no way to define which guilds go where
the problem is solved by having the database on the network
and have all shards connect to it remotely
or, using a replication system like redis does, where all machines have a full copy of the database, and they keep each other updated
im pretty much wondering if hes returning too early for what he wants to happen?
or if you wanna go a different route, you can always do a full database rebalancing/reorganizing when you change the total shards, and move all guilds to their new locations lol
ok its done
it seems just crazy to combine all the data, because it could be sharded so well too and doesnt need to reside in one database. i guess certain operations will be more costly for each entry in the database.
so what do you do when you are at the point that this combined database, where every shard connects to, bottlenecks you (assuming there is no further optimzations via cache,etc. possible)
Am I allowed to show the list of the servers that my bot is in?
your database will never bottleneck you if you use it correctly, considering its designed to handle millions of operations per second
even tough its running on one machine?
but if you ever need that kind of scaling, big services like discord/facebook/twitter/etc use ditributed database systems and horizontal scaling
but its still all over network
queries are made to load balancers, which then redirect them to instances of a clustered database either by load if the data is replicated, or by indexing, if the data is distributed
so you would still not have 1 database on each bot machine, you would have each database on a dedicated machine for the database, and communicate to it remotely from your bot machines
How i can see what server my bot in ?
How i can see what server my bot in
-_-
in which lib
discord.js
guilds property on your client
?
"who is that???"
how can u give me example code ??
guilds property on your client: the guilds property that your client instance has
dude
it's basic knowledge
@copper cradle No i dont :))
bot developer role seems loosely handed out lol
how did you code your bot then if you don't understand that
perish, help vampire โ๏ธ
maybe stack overflow
for legal reasons what i said is a joke
example code pls :))
no
try to figure it out yourself
it's just 2 words holy fuck
to get your bot's guilds you can use your client's guilds property
assuming discordjs v12, client.guilds.cache should get you started
You can even get example codes by googling, you won't get one from us
https://stackoverflow.com there you go
ew
Better than just getting spoonfed
@ Tim. So i shouldnt need any database sharding for my project forever? But then i am doing something wrong with my remote database.
When f.e. i have to reset the stats of all guildmembers of a guild, i set all the ([channel,user,values]) records to their defaults for 4 tables. This takes about half a minute for my remote mysql server. During that time it is at max capacity and wont answer other requests.
This works now, with only a few resets from time to time, but this cannot work anymore with 10x the servers..
Better than just getting spoonfed
@earnest phoenix you're saying that as if they won't find what they need and copypaste it without reading the explanation lol
I mean if you don't understand that 'your client's guilds property' means client.guilds.cache in v12 and client.guilds in v11 and < then how did you make an entire functioning bot
yep pretty much
Error: Incorrect login details were provided.
Guys, I'm getting this error, does anyone know the solution?
yes wrong token
are you sure you can't bind it to a specific permission
so i wanted to see what server my are in
guild.createInvite({ unique: true }).then((invite) => {
console.log("Your new invite link is: https://discord.gg/" + invite.code);
});
@royal portal Just do a check if they have permission to create invite links
like administrator or manage messages
That's kinda inconvenient, better check for the administrator permission or something else
i used this commands
@turbid bough its not a problem im just wondering if you guys like it or not
or yeah if its for configuration
o you mean the design
yea
i mean its pretty standard so yeah no problem with it
guild.createInvite({ unique: true }).then((invite) => {
console.log("Your new invite link is: https://discord.gg/" + invite.code);
});
idk it looks like discord
what is wrong ?
you posted it 3 times now
nice and clean and not filled with fields that arent aligned properly
or keep
so 'please make sure you have the server administrator role, then try again.'
sure
dbl is like an online class lol
well
there are numerous messages you could post there. do whatever you think sounds fine
May I ask for assistance... So im working on a addrole command, but mines doesn't seem to give the users the role mentioned, and it tells me that they already have it. but from my looks they dont.
Screenshot
code?
Yeah, 1sec
nvm
module.exports = {
name: "addrole",
category: "Moderation",
description: "Adds a role to a specific member",
run: async (client, message, args) => {
if(!message.member.hasPermission("MANAGE_ROLES")) {
return message.channel.send("You don't have permission to execute this command")
}
if(!message.guild.me.hasPermission("MANAGE_ROLES")) {
return message.channel.send("I don't have permission to execute this command.")
}
let rMember = message.mentions.members.first() || message.guild.members.cache.find(m => m.user.tag === args[0] | message.guild.members.cache.get(args[0]))
if(!rMember) {
return message.channel.send("Please provide a member to add a role")
}
let role = message.guild.roles.cache.find(r => r.name === args[1] || message.mentions.roles.first)
if(!role) {
return message.channel.send("Please provide a role to add to the member.")
}
let reason = args.slice(2).join(" ") || "Unspecified"
if(rMember.roles.cache.has(role.id)) {
return message.channel.send(`${rMember.displayName} already has the role!`)
} else {
await rMember.addRole(role.id).catch(err => console.log(err.message))
}
let embed = new MessageEmbed()
.setColor("GREEN")
.setAuthor("Role successfully Added!")
.addField("Role added to:", rMember)
.addField("Moderator:", message.author.username)
.addField("Reason:", reason)
.setFooter(client.user.username, client.user.displayAvatarURL())
.setTimestamp();
message.channel.send(embed)
}
}```
There ya go
@royal portal in your message above, you're saying a server administrator is the only role that can send invite links?
@turbid bough ^^^
yes
Guys do you know why this token error is happening?
@limpid isle https://discordapp.com/developers/applications
Integrate your service with Discord โ whether it's a bot or a game or whatever your wildest imagination can come up with.
select your application
regenerate the token
okey
copy the token, add it to the code
thanks
Where I should paste this script: if(msg.content.toLowerCase()==="cancel") return; when I write cancel, the queue I'm searching for has been cancelled, and so I can search for a new one without duplicating the search.
Script:
exports.run = (client, message, args, ops) => {
search(args.join(' '), function(err, res) {
if (err) {
if (message.deletable) message.delete(5000)
return message.channel.send('Sorry something went wrong')
.then(m => message.delete(5000));
}
let videos = res.videos.slice(0, 10);
let resp = '';
for (var i in videos) {
resp += `**[${parseInt(i)+1}]:** ${videos[i].title}\n`;
}
resp += `\n Choose a number in between: **1-${videos.length}**`;
const Embed = new Discord.RichEmbed()
.setAuthor('Searching', thumbnail, invite)
.setColor("BLUE")
.setDescription(resp)
.setTimestamp()
const filter = m => !isNaN(m.content) && m.content < videos.length+1 && m.content > 0;
const collector = message.channel.createMessageCollector(filter)
collector.videos = videos;
message.channel.send(Embed)
console.log(chalk.green('Searching for music...'))
collector.once('collect', function(m){
let commandFile = require('./play.js');
commandFile.run(client, message, [this.videos[parseInt(m.content)-1].url], ops)
});
});
}
@clear wraith first is a function, you're missing a second | in the members.cache.find() function, first() returns the value, which is a role so you don't need to get the role if you have it, you should message.mentions.roles.first() || find function like your first one does https://oliy.is-just-a.dev/zaoo4h_3789.png
to find the role
if(message.content.toLowerCase() === `${prefix}search`) {
var numbers = [ 0
];
let cdata = db.get(`cdata_${message.author.id}`)
if(cdata === 0) db.subtract(`cdata_${message.author.id}`, 30)
var answer = numbers[Math.floor(Math.random()*numbers.length)];
if(answer === 0) {
return message.channel.send(`You caught robbing a bank and paid a fine of 30 coins`)
db.subtract(`cdata_${message.author.id}`, 30)
}
var embed = new Discord.MessageEmbed().setColor("#FF4500").setTitle("**Redeem Coins**")
.setDescription(`You have found **${answer}** coins`)
db.add(`cdata_${message.author.id}`, answer)
message.channel.send(embed)
}
})```
whenever i use p!search if the winning ammount is getting in my account but whenever i lose means 0 the ammount is not subtracting from my acc.
or the user
yeah but get will return it already so why use find on it afterwards
just uses more ram and cpu
am i the only person that doesnt like writing one line if statements on the same line? lol
How i can make a invite when mys bot is ready????
npm i node-fetch -g
if (message.content.startsWith(prefix + "reset")) {
if (message.author.bot) return;
if (message.author.id !== "606279329844035594")
return message.reply("You can not use this command");
resetBot(message.channel);
// Turn bot off (destroy), then turn it back on
function resetBot(channel) {
// send channel a message that you're resetting bot [optional]
channel
.send("Resetting...")
.then(msg => client.destroy())
.then(() => client.login(token));
}``` how could i make it so it sends a message when my bot goes back up
?
your question has some grammar issues, im not sure I understand what you're asking
How i can make invite when my bot is ready, and it will console.log to me
bot.on("ready") im guessing
i tried a lot ways
do what, exactly?
:(
npm i -g node-gyp @shut inlet
@earnest phoenix stop spamming...
I have a bot cmds which send money in account of user so I am trying p!search cmd if the person wins then he gets prize in his account but if he loses the amount is not subtracting from his account
@surreal notch you are returning when answer === 0
ok
and the subtraction is not happening
@earnest phoenix client.on('ready', async () => {})
if thats what you wanted to happen
read the docs
that code never runs
yes but the invite funciton
that makes no fucking sense
so i have to remove return?
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`)
})```
what is the "invite function"
@tardy estuary
@earnest phoenix What about it?
you dont need async
client.on('ready', () => console.log())
bot.on("ready", async (message) => {
console.log(${bot.user.tag} is ready);
bot.user.setActivity("/help", { type: "LISTENING" });
bot.user.setStatus("idle");
channel.createInvite({ unique: true }).then((invite) => {
console.log("Your new invite link is: https://discord.gg/" + invite.code);
});
});
@surreal notch does the line if(answer === 0) { mean you "lose" and need to have 30 coins subtracted?


