#development
1 messages ยท Page 869 of 1
hmm thx
I NEED HELP
Im a 16YO passionate coder
im making a bot
it works fine
but it cannot do more than 1 process at a time
that means it has to complete the task it's doing to process farther info
what can i use instead of time.sleep to give my bot a delay that wont block any commands?
That command you did will straight up just not work properly
you need to have a better knowledge of asyncio if you want to make anything with while loops or doing somthing after X amount of time
doing it for fun actually this doesnt have to be that efficient. It'll be fine how it works now
just need it to do delay without blocking inputs
what i ment by that was it will not work without that knowledge
I need some help if anyone is available. Kinda new to discord.js so Id really appreaciate it if you could help
ok
nope
Alright ill try to explain
So basically i've got an api that takes a screenshot of a website and then sends that screenshot in chat whenever someone types in that command
But I want to add a command that refreshes that screenshot. (takes a new screenshot of the website)
const request = require('request');
const fs = require('fs');
request({
url: "https://api.apiflash.com/v1/urltoimage",
encoding: "binary",
fresh: "true",
qs: {
access_key: "",
url: "https://wherethefuckisxur.com/"
}
}, (error, response, body) => {
if (error) {
console.log(error);
} else {
fs.writeFile("screenshot.jpeg", body, "binary", error => {
});
}
});
Here's the code which takes the screenshot and sends it over
Im guessing I have to make it into a function to actually call it. But im unsure how to do that
a new screenshot of the website?
wdym exactly
the most simple solution is to re execute the code
But that doesnt seem to work
put the code in a function and execute it
function functionname () {
//code
}
functionname()
np
So something like this?
const request = require('request');
const fs = require('fs');
function refresh (){
request({
url: "https://api.apiflash.com/v1/urltoimage",
encoding: "binary",
fresh: "true",
qs: {
access_key: "",
url: "https://wherethefuckisxur.com/"
}
}, (error, response, body) => {
if (error) {
console.log(error);
} else {
fs.writeFile("screenshot.jpeg", body, "binary", error => {
});
}
});
}
refresh()
|| means "or" in javascript
are you talking to me ?
yes
i tried that
if(command === "rps" || "name")
it will reply to everything that starts with the prefix
if (command === "rps" || command === "anothername") {
}```
@tight plinth I get an error (cannot access 'request' before initialization)
return request({
^
function needs to return something
@blazing portal
js if (message.author.id == '364836696149458944' || message.author.id == '390969718535618561') { console.log(`Blacklisted, Skipping...`) // or message.channel.send(`rot buddy`) // or message.channel.delete() // or message.author.ban(`noob`) return; }
@earnest phoenix why do you randomly ping me?
Im trying to add it to a command so when I type !refresh it takes a new screenshot but it gave me the same error (cannot access 'request' before initialization)
I could send all of the code if that would help
it's a scoping issue, not related to return
Are you talking to me?
Yes
Did you initialise the variable request multiple times
seems like it's in a temporal dead zone
but idk
I could send the code over if that would help
too long jesus
function refresh (){
request({
url: "https://api.apiflash.com/v1/urltoimage",
encoding: "binary",
qs: {
access_key: "",
url: "https://wherethefuckisxur.com/"
}
}, (error, response, body) => {
if (error) {
console.log(error);
} else {
fs.writeFile("screenshot.jpeg", body, "binary", error => {
});
}
});
}
This is the function
And this is the command for it
well in the file you sent. your require statements were not at the top
put them at the top :)
case 'refresh':
console.log('refreshing');
return refresh()
break;
I did
They're on the top now
well, does it work now?
No
what exactly is the error (please send the error)

smhmyhead
I really appreciate it
why do you need to slow down your foreach
but why
I don't think it will
The XY problem is asking about your attempted solution rather than your actual problem. This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.
User wants to do X.
User doesn't know how to do X, but thinks they can fumble their way to a solution if they can just manage to do Y.
User doesn't know how to do Y either.
User asks for help with Y.
Others try to help user with Y, but are confused because Y seems like a strange problem to want to solve.
After much interaction and wasted time, it finally becomes clear that the user really wants help with X, and that Y wasn't even a suitable solution for X.
I mean, sure but your whole bot will stop executing while it's sleeping 
it won't respond to commands
Kts xy problem exactly ๐
Im doing a foreach
And i would like to not be that fast
LIKE ITS INSTANT
I would like to make a 30ms slow down
Is it me or is that embed really confusing to understand?
it is
I've never said anyone complain about an operation being fast
It is tho :P
that's what people want
confusing embeds = ppl trying to find logic = less questions 
there must be another solution than slowing down a for loop
cause that's just stupid
Nope because its related to discord api
I don't want to spam discord api
So i want to make a little delay between each actions
a foreach loop for what
For each server , guild size, change a channel name and a voice name
If it have too much servers, its not good
@earnest phoenix use a for loop
then delay it using a promise with a timeout that resolves in x seconds, creating a delay function.
rather than a foreach loop :^)
I'm not either, but what I provided to you is a possible solution to your issue
forEach cannot be delayed, thats why its not good to use forEach with promises
you should use a for loop
^ basically what i said
for ( const thing of array ) {
// do something
}
mhmhmhmhmhmh
Alright
for ( const client of newclient.guilds.cache.get(args[1]) {
}
Looks right 4 u ?
no
no
lmao
Of yeah true
i mean, loops are like super basic javascript
Yeah but im not used to it
you should know how to use them lol
Okay but idk what your problem or what you're trying to achieve again
javascript doesnt have a built-in way to sleep, but you can create one with a promise
(is this another xy problem in an xy problem?)
For each guild > ACTION -> SLEEP 30ms
are you trying to mass send announcements in multiple guilds 
i understand what you want to do, but you cannot do that with a forEach, you have to use regular loops
Nope i said i was using this to change the server members count
if(collected.content == 0) return message.channel.send("The user didn't answer.")```
I want to do it so if the user didn't respond with "agree" or "decline" in 10 seconds it will send that
I said for each cuz idk how to call it
Well it should be an array
(of guilds, in this case)
๐ I fell so stupid..
Alright im sure i won't understand XD shame on me
client.guilds.cache returns a collection which you can change into an array
I mean
you can try actually reading what is sent 
if(collected.content == 0) return message.channel.send("The user didn't answer.")```
I want to do it so if the user didn't respond with "agree" or "decline" in 10 seconds it will send that
@earnest phoenix
you can actually use a for of loop directly on collections
yeah
they be smart
O really didn't know that 
for of iterates over their entries, so each item will be a [id,object]
for in doesnt work tho
client.guilds.cache returns a collection which you can change into an array
I mean
you can try actually reading what is sent :bunhuhu:
Bro that looks hard idk why ๐
I never done that lmao
how would you learn if you dont at least read a bit on how things work? lmao
Im reading ๐
No point in coding something that you've already doneโข๏ธ
if(collected.content !== "agree", "decline") return message.channel.send("The user didn't answer.")```
i want it to answer after 10 seconds
reading everything
@earnest phoenix show your awaitMessage function
const filter = m => m.author.id === user.id
message.channel.send(`${user.username}, please use agree or decline.`)
message.channel.awaitMessages(filter, {
maxMatches: 1,
time: 10000 ```
@earnest phoenix you cant do something !== something,somethingElse
you have to do something !== something || something !== somethingElse
the || stands for OR
Make it so that when it's collected it runs collected.stop() if it's agree or decline
show your full code, you didnt post the last part of awaitMessages and what comes after it
if(collected.content !== "agree" || collected.content !== "decline") return message.channel.send("The user didn't answer.")```
when i reply (with anything) it will send
did someone here run a bot inside of a kubernetes? I dont really can get behind how to get different shards for every node
nope, but probably using env vars
Itay, I bet collected is a collection, check if collected.size is truthy
^ we need to see more code
where do you get collected from?
show the full code please
You defined message multiple times btw
i did ?
if (!["agree", "decline"].includes(collected.first().content)) {
//code
}```
yeah your right
you're
lmao
i dont think you get me tho
i want to do that if the user doesn't respond with agree or decline within 10 seconds it will respond
you probably also want to add the agree/decline to your filter
they want it to respond tho
If you filter it out, the bot won't respond to failed responses
i mean filter everything else out
because you can respond with anything and it will pass the filter
right, but they want it to respond "The user didn't respond" if it wasn't agree or decline
i want it so the user can respond and nothing will happen, but if he doesnt respond with agree or decline within 10 seconds it will send
That's why they should do
if(!collected.size ||
followed by this chunk of code from nmw03
(too lazy to retype sorry)
i tried using that but it didnt work
what did you try
if(!collected.size ||
followed by this chunk of code from nmw03
@spare goblet
if (!["agree", "decline"].includes(collected.first().content)) {
//code
}```
Okay no, you should be doing
if you add it in the filter, wrong answers wont do anything, it will still wait 10 seconds for the right answer
if you add it in the collected.size check, any wrong answer will cancel the waiting and say that the user didnt respond
so basically depends which behavior you want
if(!collected.size || !["agree", "decline"].includes(collected.first().content)){
}
i want it so if he doesnt respond within 10 seconds, it will send the user didnt respond, if he does respond with agree or decline it will do its thing
what if he does respond with something else?
^
it wont count, will wait
O
then you have to add it to the filter
then just add it in your filter 
can i get an example ?
i misunderstandโข๏ธ
lmao atleast you help
filter = m => m.author.id === user.id && ["accept","decline"].includes(m.content.toLowerCase())
i used that
const filter = m => m.author.id === user.id && ["accept","decline"].includes(m.content)
message.channel.send(`${user.username}, please use agree or decline.`)
message.channel.awaitMessages(filter, {
maxMatches: 1,
time: 10000
}).then(collected => {
if(collected.size == 0) return message.channel.send("The user didn't respond.")```
is this the right way ?
Bro
friendzoned
Wait
If they didn't respond agree / decline in 10 seconds
do you want it to continue waiting?
It will respond what
the user didnt respond
That was NOT what you said
looks correct
it was
You said you will make it continue to wait
i think u got me wrong
Now you're saying that, if they didn't say agree / decline and say something else, it will say "user didn't respond"
continue to wait until the end of those 10 seconds
If the user responded with anything which is not agree or decline, after the 10 seconds it will say "User didn't respond"
If the user responded with agree or decline within 10 seconds, it will continue
...SMH
try it and see if you like it or not
no use the filter
No
They sia dthey want it to respond even if the person responds something irrelevant
See?
BRO
user didnt respond should be equivalent to no collects
if he doesnt respond with agree or decline within 10 seconds it will send that he didnt respond
if he did respond with agree or decline it will continue
so it will still resolve an empty thing
thats what i meant
IF
therefor replying with user didnt respond
it wont pass the filter, maxMatches wont match, time will continue waiting until the 10 seconds pass
after 10 seconds it resolves with an empty collection
oh if thats what you
if he will respond with what, it will wait until the 10 seconds end

maxMatches only collects that amount of matches
and if they didnt respond with agree or decline within 10 seconds it will respond
yes, everything else gets ignored
so the only possible outcomes will be an empty collection, an accept or a decline
help what code js let commandfile = bot.commands.get(cmd.slice(prefix.length)); ERROR js TypeError: Cannot read property 'get' of undefined
bot.commands is not defined
module.exports = async (bot, message) => {
const Discord = require("discord.js");
var con = bot.con
con.query(`SELECT * FROM servers WHERE sid = ('${message.guild.id}')`, (err, rows) => {
if(err) throw err;
if (rows.length === 0) {
con.query(`INSERT INTO servers (sid, name, prefix) VALUES ('${message.guild.id}', '${message.guild.name}', '-')`);
console.log("New Server ADDED \n Succesfully SAVED!!" )
} else {
var prefix = rows[0].prefix
if (!message.content.startsWith(prefix)) return;
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) commandfile.execute(bot, message, args, con);
}
});
//code
}```
WHY UNDIFEND
it has been good so far
@earnest phoenix What is undefined
Where do you define it?
in async (bot, message) probably
yeah, iirc bot is the bot object itself
bot doesnt naturally have a commands attribute
o shit js bot.commdans = new Discord.Collection(); misspelled
That will be it
does anyone know how to make your bot not entirely respond to you but just say the message
@lucid pasture in what context
like it says for example @lucid pasture, Hello
kk
can anyone help me with setActivity
it stops working after a day
there's no errors
im using pm2
discord.js
but then when I use my restart command
process.exit
it fires the ready event again
and it works
not sure why it only works for a day
put your activity in the client options
please
stop
talking
like
that
plz
otherwise it may be lost if it disconnects and reconnectes
would i use client.on disconnect?
no
@tight plinth I am sure they did it unintentionally but you don't need to repeat it to make a point.
still
autoreconnect?
@royal portal js new Client({ presence: { activity: { type: "bla", name: "bla" } } })
put it in your client options
instead of the ready event
I dont have the options
where
where i said
where you do new Client()
or new Discord.Client()
put that inside Client
const client = new.Discord.Client(); ?
const Discord = require('discord.js');
const client = new Discord.Client(new Client({ presence: { activity: { type: "bla", name: "bla" } } }));
new Client({
presence: {
activity: {
type: "bla",
name: "bla"
}
}
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
no idea
like this
const Discord = require('discord.js');
const client = new Discord.Client(new Client({ type: "bla", name: "bla" });
new Client({
presence: {
activity: {
type: "bla",
name: "bla"
}
}
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
const client = new Discord.Client({
presence: {
activity: {
type: "bla",
name: "bla"
}
}
})
I just released my bot a minute ago. How long does it take it to get verified on top.gg?
const Discord = require('discord.js');
const client = new Discord.Client({presence: { activity: { type: "bla", name: "bla" }}});
new Client({
presence: {
activity: {
type: "bla",
name: "bla"
}
}
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
@hybrid panther a few days, up to about 2 weeks
Kk
like that?
no
dont remove presence and dont remove activity
and remove that extra new Client
you didnt close it correctly
literally, just take this
and make it your Discord.Client
jesus
yes, everything that is inside the ()
do I need the 'new' part
quick question with djs : whats the fastest between js message.channel.send(new Discord.MessageEmbed() .setColor("YELLOW") .setTitle:("TEST"))
and js message.channel.send({embed: {color: 0xffff00, title: "TEST"}})
in term of "loading"
const Discord = require('discord.js');
const client = new Discord.Client({presence: { activity: { type: "bla", name: "bla" }}});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
yes, finally
now remove the other Client
and of course, change "bla" to your activity
the type is playing listening and watching?
ok
by a few microseconds probably
I am tryna move to mysql db and I'm not sure how to do queries and how to connect to it
Well I have a choice of any of these databases
error
the SQL language is mostly universal
the only thing that changes is which library you use, and how the library does the queries
cannot access client before initialization
What did you put as the status
type watching
const Discord = require('discord.js');
const client = new Discord.Client({presence: { activity: { type: "WATCHING", name: `${client.guilds.cache.size`}}});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
If you wanna show server count or something
that will not work
that can only be used inside the ready event like you had before
client.user.setActivity({type: "WATHING",
name: `${client.guilds.cache.size}`})```
and if i use restart cmd, it comes back
same for you?
really
then make an interval where it re-sets the status every 30 minutes
I wasn't sure how to do that
var activevar = ["with the &help command.", "with the developers console", "with some code", "with JavaScript"];
var activities = activevar[Math.floor(Math.random()*activevar.length)];
client.on('ready', () => {
client.user.setActivity(activities);
}
something like that
client.on("ready", () => {
client.user.setActivity(...)
setInterval(() => {
client.user.setActivity(...)
}, 1800000)
})```
yeah but that doesn't keep looping it
ohhhh
mine's not changing
client.on('ready', () => {
client.user.setActivity(`test`, { type: 'WATCHING' });
setInterval(() => {
client.user.setActivity(`${client.guilds.cache.size} guilds| discord.js `, { type: 'WATCHING'});
}, 1800000)
});
I wish dnd would work
const client = new Discord.Client({ fetchAllMembers: false,
disableMentions: "all",
messageCacheMaxSize: 0,
presence: {status:"dnd"} });``` would this show dnd?
@golden condor does the setInterval work
yes
how do you know
would this work
client.on('ready', () => {
client.user.setActivity(`${client.guilds.cache.size} guilds | discord.js`, { type: 'WATCHING' });
setInterval(() => {
client.user.setActivity(`${client.guilds.cache.size} guilds | discord.js`, { type: 'WATCHING'});
}, 1800000)
});
and if i put console.log("Logged in") at top will it say that in console every 30 seconds?
quick question with djs : whats the fastest between
@tight plinth the second one is shorter, so should be used as its faster to type as long as its still readable
by deleting it
nobody likes to type out, or maintain boilerplate code
and making a new one
ill try
Ok
i can do dbname.delete(message.guild.id) tho
and then re-create it
but idk if dbname.delete is a real thing cause it doesnt seem to be in docs
bruh
of course it wont tho
but idk if dbname.delete is a real thing cause it doesnt seem to be in docs
programming is all about making errors and learning from them
if u say it wont work
quit programming
i know it wont work
and i tried it already
@royal portal this means 1800000 milliseconds (30 minutes)
so it will only run every 30 minutes
@finite bough lets keep memes & shitpost to off topic
if(command === "reseteconomy") {
await coins.delete(message.guild.id)
}```
you can also do 1000 * 60 * 30 itll be maybe easier to understand
@quartz kindle so the part after setinterval will run every 30 mins?
the part INSIDE setInterval
ah ok
@earnest phoenix can u show the error u get
im not getting any
this part
and its not working?
no
hmm
if(command === "reseteconomy") {
db.delete("coins", message.guild.id)
}```
why wont this work
no errors?
no errors
glitch?
yes
can u run the command and refresh in the terminal?
ok
@quartz kindle quick db uses sql to store data right?
same thing
same thing
i used both tho
coins.delete(message.guild.id)
db.delete("coins", message.guild.id)
i tried both
i dont think so
db.set(message.guild.id, {coints : 0}
coints*
didnt work
(โฏยฐโกยฐ๏ผโฏ๏ธต โปโโป
ok lesson 1
i would rather use json db than using quick db
it corrupts u
@nocturne dagger is there any way for me to get a custom font onto my bot's page?
thanks for your help ๐
@placid crown only some people can use css and other stuff to customize their bot page
what do you mean by that @finite bough
certified bots are among the example
i am able to edit my page
i just don't know enough css to get a custom font on there
lol
so i have this font
fonts?
in a .otf
and i want my bot's name on it's page to be in that font
i don't think it's a common font so I can't just put its name in the css
i have to give it the file too
Burbank
i never really used css that much but thats what i found and what makes sense
nah didn't work
i think it's because burbank isn't a well known font
so it's necessary to provide the otf file
if it's a custom font you'll have to load it with the url
thanks i'll try that ๐
specifically this part https://css-tricks.com/snippets/css/using-font-face/#article-header-id-4
yes
i'm confused on how to do that part
use a vps
@font-face {
font-family: "Whatever";
src: url("https://yeet.com/Whatever.ttf");
}
it can be a direct https/http
and then you just set that as a font for everything
https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face explains it better
i'll check it out thanks
Anyone know what kind of specs the big bots like mee6 and such need for hosting?
their support servers would know more
mm
Tru
Just curious
show your code
wait
const Discord = require("discord.js");
module.exports.run = async (bot, message, args, command) =>{
//let bicon = bot.user.displayAvatarURL;//
god = bot.guilds.cache.reduce((a, b) => a + b.memberCount, 0).toLocaleString('en') / bot.guilds.cache.size
god2 = bot.channels.cache.size / bot.guilds.cache.size
god3 = bot.guilds.cache.size / 2500 * 100
var days = Math.floor(bot.uptime / 86400000)
var hours = Math.floor((bot.uptime % 86400000) / 3600000)
var minutes = Math.floor(((bot.uptime % 86400000) % 3600000) / 60000)
var seconds = Math.floor((((bot.uptime % 86400000) % 360000) % 60000) / 1000)
let CPU = Number(Math.round((await new Promise(async r => {
let start = [process.hrtime(),process.cpuUsage()];
await new Promise(r => setTimeout(() => r(),100));
let elap = [process.hrtime(start[0]),process.cpuUsage(start[1])];
r(100.0 * ((elap[1].user / 1000) + (elap[1].system / 1000)) / (elap[0][0] * 1000 + elap[0][1] / 1000000));
}))+'e2')+'e-2')
let botembed = new Discord.MessageEmbed()
.setColor("#FFD700")
//.setThumbnail(bicon)//
.addField('Bot information',`
Bot name: \`\`${bot.user.username}\`\`
Bot create at: \`\`${bot.user.createdAt}\`\`
Bot creator: \`\`ใShiro-chanใ\`\`
Code line :\`\`1509\`\`
Total Commands enable : \`\`14/21\`\`
Premium buy : \`\`2 (after new update)\`\`
Loli girl earning :\`\` 0 USD /count from new update beacause not complete request\`\`
Top buy (show 3) :
\`\`1.DemonX : 70 USD (Special pre)
2.Andrey-chan : 69.96 USD (Special pre)\`\` `)
.addField('Bot stats',`
Total: \`\`${bot.guilds.cache.reduce((a, b) => a + b.memberCount, 0).toLocaleString('en')} Users |2mins count delay\`\`
Total: \`\`${bot.channels.cache.size} Channels\`\`
Total: \`\`${bot.guilds.cache.size} Servers\`\`
Avg~: \`\`${god2} Channels/Servers\`\`
Avg~: \`\`${god} Users/Servers |5mins count delay\`\`
`)```
@summer torrent
bot.guilds.cache.reduce((a, b) => a + b.memberCount, 0).toLocaleString('en') is a string
because .size returning as number
@summer torrent so what i should do
remove toLocaleString
@quartz kindle remove .toLocaleString('en') right
you're converting number to string
imagin only having half a gb of ram
its enough ram if you know what you're doing :3
imagine having 64kb of ram and a 2mhz cpu?
@finite bough heroku
i do not have moneyyy
poor girll
@finite bough bot will auto reset
do not worry
heroku and glitch had same specs
@nocturne dagger actually have 256 heap ram
if you know what you're doing

a modified discord.js lib
memory: 106.45
if my bot under 1000 guilds
106.45 seems possible
use shard = 2 will divide ram / 2 right ?
if you use sharding, you will have two processes
@quartz kindle for the setInterval, if I have something like ${client.guilds.cache.size} does that refresh it every 30 minutes
client.on('ready', () => {
client.user.setActivity(`${client.guilds.cache.size} guilds | discord.js`, { type: 'WATCHING' });
setInterval(() => {
client.user.setActivity(`${client.guilds.cache.size} guilds | discord.js`, { type: 'WATCHING'});
}, 1800000)
});
so instead of 1 process with 200mb ram, you will have 2 processes with ~150mb ram each
if you use internal sharding in discord.js v12, then you will still have 1 process
with normal sharding, the shard would crash, and be restarted yes
@royal portal yes
@quartz kindle where is your bot
reee need certifed from top .gg and discord
i use galaxygate for hosting
@summer torrent i forget it
=)) poor and stupidd girl
you have 30 000 users + by me =))
tks for support me now i support you
that just means more cpu usage lmao
check the help command
in the help command, click charting commands, then click new chart, then click examples
its an Astrology chart
Lol
Astrology is the art of reading a person's life using the positions of the planets in the sky
reee
its widely known as pseudoscience/divination, although those descriptions are not exactly accurate
this is #memes-and-media xd
let channel = message.mention.channels.first() || message.guild.channels.get(args[0]) || message.guild.channels.find(c => c.name === args[0])
^??
looks good
hehell
Why this donโt good ?
if(Guild_Data.get(`${server}.lang`) === "fr") || if(!Guild_Data.get(`${server}.lang`)) {
hello im new
i just developed a swear filter
events.js:173
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property 'channels' of undefined
at /app/commands/welcomechannel.js:28:37
at /rbd/pnpm-volume/034599ea-c1c3-422b-9783-c3b2bb2163b1/node_modules/.registry.npmjs.org/mongoose/5.9.7/node_modules/mongoose/lib/model.js:4837:16
at /rbd/pnpm-volume/034599ea-c1c3-422b-9783-c3b2bb2163b1/node_modules/.registry.npmjs.org/mongoose/5.9.7/node_modules/mongoose/lib/model.js:4837:16
at /rbd/pnpm-volume/034599ea-c1c3-422b-9783-c3b2bb2163b1/node_modules/.registry.npmjs.org/mongoose/5.9.7/node_modules/mongoose/lib/helpers/promiseOrCallback.js:24:16
at /rbd/pnpm-volume/034599ea-c1c3-422b-9783-c3b2bb2163b1/node_modules/.registry.npmjs.org/mongoose/5.9.7/node_modules/mongoose/lib/model.js:4860:21
at /rbd/pnpm-volume/034599ea-c1c3-422b-9783-c3b2bb2163b1/node_modules/.registry.npmjs.org/mongoose/5.9.7/node_modules/mongoose/lib/query.js:4370:11
at /rbd/pnpm-volume/034599ea-c1c3-422b-9783-c3b2bb2163b1/node_modules/.registry.npmjs.org/kareem/2.3.1/node_modules/kareem/index.js:135:16
at processTicksAndRejections (internal/process/task_queues.js:81:9)
Emitted 'error' event at:
@finite bough define channels
Why this donโt good ?
if(Guild_Data.get(`${server}.lang`) === "fr") || if(!Guild_Data.get(`${server}.lang`)) {
do you have 2 if statements on the same line?
@finite bough is it a DM?
that's not how js works
nope
if(condition1 || condition 2)
You need to remove the second if
Ok
why do i always make the smallest mistakes possible in history of discord
@amber fractal
you didn't remove a )
is there a good chance a bot gets added?
you close the if then do a ||
@earnest phoenix depends upon ur bot
show the line you have now
@finite bough if(//code||//code){//code}
why did u send me that^?
oh
that would error but sure
it was meant for the other person
i thought somebody was learning to make an if statement
so add a function to turn it off atleast
if(condition1 || condition || conditionx){
}```
that's if statement syntax (using `or` operators)
how would i do a randomized response for a command in discord.js 12
put all responses in an array
then call array[Math.floor(Math.Random() * array.length)]
thanks
this is not related with your discord.js version ๐ค
?
it should show only permissions that are specific to that channel
what you can see in channel permissions on discord
ah ok, nvm i cant use that
i need to check if a bot has permission in that channel or not
or maby i should have just checked if the bot has permission at all and
you can use something like channel.permissionsFor
yeah, unfortunately that library does not have that
which library?
ah
but just checking role permissions should be enough i guess?
Im trying to find a way to get a user trought id in voicechat and remove the voicemute
let channel = client.guilds.cache.get("688151170971336735").voiceChannel;
for (let member of channel.cache.members) {
if (!member.id == "425328259056664596") { return; }
member[1].setMute(true)
}
}
no, thats incorrect
that means NOT member.id EQUALS "xxx"
if it doesnt exist, it will turn it into true
so the end result is true/false == "xxx"
which will never work
I kinda found a way
what you want is != or !== which means NOT EQUAL
client.on('voiceStateUpdate', (oldState, newState) => {
if (newState.id = "425328259056664596") {
if (newstate.serverMute == true) {member[1].setMute(true) }
}
});```
How can i edit member[1].setMute to user id ?
thats also wrong, youre using =
what is member[1]?
Idk
i copied that
shall i do
client.on('voiceStateUpdate', (oldState, newState , member) => {
then just member.setMute(false)
you should stop coding blindly and actually trying to understand what you're doing lol
what do you even want to do?
if user.id get muted
then unmute him
๐
I have a coin system and i want the bot to use , for example: instead of 2000, it will be 2,000
you can use .toLocaleString for that
how can i
2000.toLocaleString
I was trying to publish my package but I get the following error: -
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/disco-oauth
npm ERR! 404
npm ERR! 404 'disco-oauth@4.2.5' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
I get this error despite the fact that I'm the author and am logged in in the CLI.
there is nothing such as "https://npm.pkg.github.com/disco-oauth"
Although the package already exists at https://npmjs.com/package/disco-oauth
Oww
Is the Github acquisition of npm the reason behind this issue? @turbid bough
you're trying to publish a package you made?
I am trying to publish some changes to a package I made long ago. @quartz kindle
using npm publish?
yes
change your npm login registry?
hm?
@earnest phoenix you have newState and newstate
npm login
did you bump the version numbers?
wdym by "bump"
change the version numbers to reflect the update
yes
@quartz kindle what do you mean
i think he is trying to upload 4.2.5 so yeah its bumped
im not sure, i've never used npm publish directly, i use np to publish mine
if(args[1] === "all") return coins.subtract(`${message.guild.id}.${pUser.id}`, parseInt(all)).then(message.channel.send(removedallcoinsembed))```
Tried to remove all coins from a user, coins are now stuck on 0
Wait what's np?
if(args[1] === "all") return coins.subtract(`${message.guild.id}.${pUser.id}`, parseInt(all)).then(message.channel.send(removedallcoinsembed))```
Tried to remove all coins from a user, coins are now stuck on 0
you might have accidently changed to a github registry i guess
ooh
I haven't touched the package.json a single bit since the last time I published it @turbid bough
@earnest phoenix
except for the version bump
oh yeah my bad
in d.js, is there a way to check if a voice channel is joinable? for instance, either the voice channel is full or the bot doesn't have permission. i want some error message when someone tries to do that rather than it just being silent
i tried evaluating member.voice.channel but i can't seem to find anything
if(args[1] === "all") return coins.subtract(`${message.guild.id}.${pUser.id}`, parseInt(all)).then(message.channel.send(removedallcoinsembed))```
Tried to remove all coins from a user, coins are now stuck on 0
let all = coins.fetch(`${message.guild.id}.${pUser.id}`)```
wdym stuck at 0
You might get more help from discord servers thats for bot developers
its now 0
wont change
change by what
(node:25157) UnhandledPromiseRejectionWarning: TypeError: Target for .subtract(695319481609879582.336885192490745858, NaN) is not a number.
the coins
if i try to add
it wont work now
this is the error
you tried to subtract NaN
but i used parseInt(all)
let all = coins.fetch(`${message.guild.id}.${pUser.id}`)```
console.log(all)
Hey
I'll just use np myself. Thanks for the suggestion @quartz kindle
yeah give it a try
@indigo folio voicechannel.joinable
@earnest phoenix its a promise, then you need to await it
oh shit thanks
i tried using await
(node:25436) UnhandledPromiseRejectionWarning: TypeError: Target for .subtract(695319481609879582.336885192490745858, NaN) is not a number.
how did you try using await
console.log it
send what you did
let all = await coins.fetch(`${message.guild.id}.${pUser.id}`)```
its null
maybe because i have no coins ?
yeah the db crashed after the mistake with all
i will redo it
working now
thanks Tim!
btw i tried using .toLocaleString but it says ```js
function toLocaleString() { [native code] }
let usercoins = await coins.fetch(`${message.guild.id}.${message.author.id}`).toLocaleString```
i used that
nvm i did it
Where in this i can find when a user is voice disconnected ?
....what is that?
connection and channelID
if they exist, the user is connected
if they dont exist, the user is disconected
is there a way to know if the user disconnected or got voice kicked
Same for move, moved or changed channel
voiceStateUpdate
voiceStateUpdate gives you old state and new state
if oldState has a connection, but the newState doesnt have a connection
that means the user disconnected
you can fetch "usermove" from audit logs
you'd still have to use the event to know when to fetch it, which voids the use of audit logs in the first place lol
Alright so let's pretend i just compare oldState and newState, how can i move my user to oldState*, should i just get client and then move him ?
how can i make it so if a number is not a whole number it will return a message?
0.50 for example
.isInteger()
guild.fetchAuditLogs({type:20}).then(audit => {
const executor = audit.entries.first().executor;
let member = guild.members.get(executor.id)
if (!config.whitelist && !config.bypass && !config.owner); {
member.ban({reason:"Unathorized member kicked a user manually."})
}
})
.catch((err) => {
console.log(err);
})
});```
What's the error?
wym
Is this discord.js?
mhm
Do you have any errors?
there is no guildKickAdd lol
MEMBER_KICK
there is no MEMBER_KICK
audit event yes...
You might have to change it from stable depending on the version your are using.
there is no kick event
u have to get the kick from audit no?
How can i check if a number is a whole number?
I tried using .isInteger but it doesn't seem to be working?
audit logs are not client events
@earnest phoenix those are audit log events
yes
guild.fetchAuditLogs
The number must be inside ()
Number.isInteger(0) //true
Number.isInteger(0.5) //false
Number.isInteger('123') //false
this weird lmao
uses NaN
Alright so let's pretend i just compare oldState and newState, how can i move my user to oldState*, should i just get client and then move him ?
(repost)
uh wdym
@elder vine i used it but now whatever number i use it will say its not a whole number?
isNaN is for letters yes
isInteger should work
what are you trying
if a number is not whole, return message
like if its 1 then nothing and if its like a then return?
if (Number.isInteger(args[0])) return;
i tried that
if(Number.isInteger(parseInt(bet))) return message.channel.send("T")
bet is args[1] btw
ok
when i log req.ip in express i get ::ffff:<xxx>.0.0.1
but when i look to my ip in a website like http://api.ipify.org/ it shows a other ip ๐ค
it still works
if(Number.isInteger(args[1])) return message.channel.send("T")```
i used 100.5
and it worked
Can't you just use Math.floor()?
hmm
or Math.round()
i would use typeof in most cases
no
oh

