#development
1 messages Β· Page 850 of 1
Yea
You can use something like this
const list = [
"this is one",
"this is two",
"this is three",
"this is four, and you can do more"
];
client.on('ready', () => {
setInterval(() => {
const index = Math.floor(Math.random() * (list.length - 1) + 1);
client.user.setActivity(list[index]);
}, 10000);
});
avoid spoonfeeding
^
instead instruct them on how to do it, but don't give them working code they can copy paste
Well, sometimes you gotta learn code by reading code.
learn? they won't learn anything. they'll ctrl+c ctrl+v and forget about it
it's why spoonfeeding is so discouraged
you want to push the person to do some research for themselves and figure out how it works themselves
Is there a plugin to autoadd semicolons in nodejs/vsc
i like having em to make my code readable
probably
@earnest phoenix https://www.google.com/search?q=auto+semicolon+vscode
life saver
i found https://marketplace.visualstudio.com/items?itemName=vmsynkov.colonize but u still gotta type it
like wtf lol
xD
@earnest phoenix use a linter?
/rbd/pnpm-volume/96be643d-4ea6-4656-8d52-496cc3b5a5a9/node_modules/quick.db/node_modules/bindings/bindings.js:135
on glitch
nvm uninstall and installed and it worked
anyone here knows why when i press enter in spyder console it wont do anything?
hey ? bot.user.displayAvatarURL not working
Just use ESLint like you should be already @earnest phoenix
When using ESLint you can force vscode to auto-lint on save.
@earnest phoenix what version of Discord.js are you on.
learn? they won't learn anything. they'll ctrl+c ctrl+v and forget about it
not true i actually learned alot of what i know by doing this
reading someones code and making it my own
so if i need to find out how to do a certain thing id search for it on stack or something and get the general idea then write my own code based on it
add a ()
@earnest phoenix lets just do our job its upon them if they want to learn or not
if they are willing they will learn it or else they will just copy paste
u cant make them do anything by force
pushing people to get and learn how to use the resources they have helps them more than just giving them the answer.
google is your best resource
Hi guys i have a question. I am trying to optimize memory usage but i couldn't solve that. When i play a music and skip that in discord, ytdl continue to read stream from youtube. How can i solve this problem ?
How am I able to see the bot's uptime?
in seconds, minutes and hours?
I have that, however, doesn't work
in discord or console ?
you can define a async function and you can assign it to a variable every minute
with setTimeout() function
@gray pagoda how are you calling that code?
and what does it return?
if thats all the code, then its not even returning anything
didnt see u in a while tim
long while
@quartz kindle as a module
var minute;
function sleep(){
return Promise(resolve =>{setTimeout(resolve,60000)});
}
client.on('ready',() =>{
while(true){
sleep().then(() =>{
minute += 1
});
}
});

what the fuck
wath?
for uptime
?
My brain: Task failed successfuly
i don't understand what is problem ?
that code will make your process crash by infinite loop
No there is promise function
remember that I need the seconds then I do math from there to get the hour and all that, and process.uptime is a thing
you are creating infinite promises
and not awaiting any of them
just delegating them
also, you dont even need to count time
yes its true
the process already does it for you
the problem is that it overwrites it when you put it in a loop
const up = require('./uptime');
let currTime = parseInt(Math.floor(process.uptime()));
let arrayReturn = [];
setInterval(function () {
arrayReturn = up.uptime.uptime(currTime, 'array');
}, 950);
setInterval(function () {
console.clear();
if (arrayReturn[0] > 59) {
arrayReturn[1] = arrayReturn[1] - 60;
}
if (arrayReturn[2] > 59) {
arrayReturn[2] = arrayReturn[2] - 60;
}
if (arrayReturn[3] > 59) {
arrayReturn[3] = arrayReturn[3] - 60;
}
if (arrayReturn[4] > 59) {
arrayReturn[4] = arrayReturn[4] - 60;
}
console.log(arrayReturn);
}, 875);
uptime has the function I sent on the ss, and returns it in an array
return [seconds, minutes, hours, days, months];
why are you running a 1 second interval
using the same uptime
i see you're trying to get the time to show in the console in real time, but why?
^
that will prevent you from using the console for other things like logging
he clears console every second
thats even worse
i see you're trying to get the time to show in the console in real time, but why?
@quartz kindle I want to do it because I want to have real time info, not just a static log
by sacrificing your entire log capabilities?
and not console
you cant log when it's constantly cleared
@amber fractal you can, it's logging every second, then clears it
then log it again
should I use async await?
i mean, if you want real time info, just use a process manager
pm2 has a monitor mode
^
or use uptime robot
wat
it shows the uptime
you can use my code with awaiting the sleep function π
we are not talking about node project hosting
lmao
you could use any other application that monitors other applications
like tim said
@gray pagoda if you do it like you're trying to do, you will lose the ability to use console.log for other things. so please dont do that lol
pm2 has a monitoring mode
if you absolutely want to do that way, you need to create an entire logging system to not lose your other logs, which is basically reinventing the wheel
like a command handler uses other command files to execute commands
i am adding a logging system in my bot that logs, create channel, msg delete.. bla bla
is it a good idea to move that shit in some other file
@gray pagoda if you do it like you're trying to do, you will lose the ability to use console.log for other things. so please dont do that lol
@quartz kindle Then I'll try to do it every 2 seconds
personal preference i guess @finite bough
I'd explain but idk how to, my brain made this complicated thing that I can't decrypt to english xD
I'll find a way to show life stats about he project and the bot
somehow
no, I am just testing

no Discord.js imported
but are you planning to put it inside the bot?
yes
My offer is still valid π
then for example if you do console.log(command) or whatever, when your bot users use commands, the log will be deleted every second
how do you plan on dealing with that?
it will loop, it will send an array with the last command use, and it will pass it to the console log and check if it exist, if it dosn't then not print i
very hard to explain
commands are not the only thing which are logged
how would you log errors?
^
how would you see past errors to fix them?
comment the stats
let lastCommand = [];
setInterval(funtion(lastCommand, time){ console.log(...); }, 2000);
// bot.on :
case 'commad':
lastCommand.push('commad')
break;
my idea
ok but then you need to do this for EVERYTHING, all errors, all logs, all possible situations. and also, this will make your process use a LOT of cpu
ik
and you need to regularly clear it
yes
to avoid making the list too long
then good luck lol
I just need the way to get the time
I can get the time but then It goes like seconds: 300
if I do if (seconds > 59){ seconds = seconds - 60 }
but then it sets it to 0
you need to call process.uptime() from inside your uptime function
and not store it in a variable outside
else it wont get updated
and you dont need to use -60, you can use modulo
75 % 60 = 15
modulo ftw
I did it this way: parseInt(Math.floor(seconds/60), 10);
you are doing a huge pile of unnecessary operations
the whole thing can be greatly simplified
Using discord.js, I have a cron job on my Ubuntu server to run a script to start my bots but for discord.js bots it always gives this error
When I run it myself it works fine
wrong node.js version
what does [fs] readfile do?
@quartz kindle you sure? It only gives this error when it's running as a cronjob
I have two questions
1. Why should everything change?
2. Where can I see the changes?
pl: ${bot.guilds.size} not working
your cron job is using the wrong version
cron runs process as a separate user
so its possible that its using different settings
you might need to force cron to run with the correct user or the correct version
async loadCommands()
{
const dir = `${process.cwd()}/commands`;
const files = await readdir(dir);
if (files.constructor.name === 'Array' && files.length == 0)
return;
for(const file of files)
{
let module = new (require( dir + '/' + file ))('test');
let proto = Object.getPrototypeOf(module);
let methods = Object.getOwnPropertyNames(proto)
.filter(item => item !== 'constructor' && typeof proto[item] == 'function');
for (const method of methods)
{
this.commands.set(method, {
proto,
method
});
}
}
}```
Is there a better way in which I could write this?
I have two questions
1. Why should everything change?
2. Where can I see the changes?
pl: ${bot.guilds.size} not working
https://discordjs.guide/additional-info/changes-in-v12.html @earnest phoenix
@quartz kindle can I force it to run it as just me
Also are you sure it's a seperate user on Ubuntu? I can't seem to find anything about this user online
tim comes back and all the questions too
@quartz kindle
Hi guys i have a question. I am trying to optimize memory usage but i couldn't solve that. When i play a music and skip that in discord, ytdl continue to read stream from youtube. How can i solve this problem ?Do you know the answer to this question?
Also it pulls from my git fine so it definitely uses my ssh keys at least
okey
Most things like that use .cache now.
If you wish to add to the collection you need to use fetch.
I'm looking for an API for uploading images but with no authorization needed because I'll be using it client-side, if anyone has any suggestions that'd be grand
@sullen salmon
Crontab runs shell script as root by default, that means it's using the root user node.js instead of the node version which you are using to run the script
If you have root privilege, you can check root user node.js version by,
$sudo su
$node -v
from stackoverflow
Petition to rename this chan "Tim's house"
That might be outdated, but anyway root has same node as my user
then make it console.log(process.version) and see what it outputs when it runs from cron
whats your current node.js version btw?
and how did you install it?
can you color links in your embed? PL:
I mean maybe
Do decorators in plain js exist?
well if u want to colour them
Just checked with whoami and the process is definitely being run as me @quartz kindle
@sullen salmon but did you test the node process version from within the script? because the error you posted is related to that
thats a hyperlink
@quartz kindle I'm on mobile so it would be a hassle to do that so how would that help exactly
to confirm it lol
but anyway, try adding the absolute path to the correct node version in the cron job
how do i know what color js .addField(`Library`, `[discord.js](https://discord.js.org/#/)`, true)
is that even possible?
yea why are you using ` and not '
do not know just saw it on the net
link?
const embed = new Discord.RichEmbed() .setAuthor(Hibiki | ιΏ, client.user.avatarURL) .addField(Version, 1.0, true) .addField(Node JS, 8.11.3, true) .addField(Library, `[discord.js](https://discord.js.or...
Lul
undifend @earnest phoenix I think you meant undefined
just because no hits were specified
looks like discord mods idk
you can't do it?
nope
i am sad π’
you may get banned if they discover you're using client mods
with they I mean discord
imagine if discord allowed css in embeds
but it would have been so nice
Oof
shurimashurimashurimashurimashurima
yeah
Imagine Discord actually listening to bot devs and adding useful stuff /s took them years to implement stuff like whitelisting pings instead of hacky methods
they should at least allow the use of full markdown
thanks for the information
Like having
Welcome
rules
in a channel would look neat
sometimes its simply too difficult to add certain features
yeah
ie: it requires a rewriting a large part of the code base
tbh they should've added it from the very beginning
Discord was not as big as this at the beginning so they probably diddn't even think of it as useful
the absolute worst thing in software engineering is
client: "i want to add XYZ"
dev: "WHY DIDNT YOU SAY SO BEFORE??? NOW ITS TOO LATE"
lmao
:cuddle:
wanna hear something even worse?
actually asking the client for their opinion during development, them saying it's fine, and then at the final stages complaining about the thing that they said was fine
That's why you dont ask for opinions 
Nah Cry, they say the opinion is fine but then tell your boss getting you in trouble
because big brain
lmao

does pm2 monit have any effect on the processes?
None that I noticed @grizzled raven
ok
I run fighting game servers. We use webhooks to get specific information when a # is used from twitter. (IFTTT runs the webhooks)
Is there a way for all post in a specific channel to receive a up/down vote? (if downvote exceeds a number the post is deleted and if upvoted it stays)
or can the bot do wehooks with this option?
A bot would be able to do that yes
ok so i see d.js v12 is
very different from v11
whats this message.channel.cache stuff i see
Who knows what the new 'get' is?
or something similar to it
for discord.js
well
it takes the code from a site
res.body.file
it sets the image to that
so like random cat command
im not asking for your get function
takes from https://aws.random.cat/meow
i didnt know you can do http requests with d.js
oh
You can just use snekfetch?
^
I thought snekfetch was dep or outdated?
@knotty steeple cache is the collection of stuff we already had in djs 11
for example, client.channels.cache replaces client.channels
client.channels is then used as a manager, where you can fetch a channel from discord and other stuff
i think he asked the get function of snekfetch or something like that, not d.js
dont use snekfetch then
node fetch
how many servers does your bot need to be in in order to be able to shard? or can it shard straight from 2?
technically you can shard whenever
^
you can shard at 1
u can have 1 server and have multiple shards
but there is no reason to
ok good
if you shard at 2 servers with 2 shards, would you have 1 shard per server?
how does it depend on the server id
because of the formula that decides which server goes to which shard
do you know the formula or you just know it exists?
@quartz kindle if I ever need to shard in the future im coming to you, docs or no docs xD
lmao
theres a bot thats on 270 servers with 10 shards
and one thats on 17 servers with 8 shards
im at 1700 and i still havent sharded
Ooof
i need to finish this current update first thouuuugh
i went past 2500 without sharding
bad
i had to start autoleaving guilds until i finished my update
Oof
Depends
well it took me 3 months to go from 0 - 1700
lmao
if you're using discord.js v12 just use internal sharding
well im at exactly 100 days (woohoo) and im at 1660
80
by internal you mean d.js' sharding manager, right?
nope
internal sharding = shard:"auto"
basically multiple ws connections under the same process
so like
uh
oh wait
oh okay so just dont do anything and put shards: "auto" innthe client?
yeah thats what i meant
yeah
yup
but would it work like the sharding manager, where you can broadcast eval and have to fetch stats?
no, you dont have to
all guilds are cached in the same process
so they are all available
you can do client.guilds.cache.size and get 5000+
is it like the two client's guilds in one collection, but then to discord they have two different sets of guilds?
if that made sense
nope, its all in the same collection
the only difference is that each guild has a shardID property
would doing that in d.js v11 be any different?
v11 doesnt have that
this isn't related to bots but would it be better to use a memory cache or disk cache
memory cache as much as possible
i hate when i become a whitename
disk as minimum as possible
one last question, would you say i'm better off rewriting to discord.js v12 and then sharding, or shard now, then rewrite after
i did both at once
even when the items in the cache are images?
for images it depends
you rewrote to djs v12, sharded, then rewrote again? 
i think if you suspect your bot is going to get big, go ahead.
isn't related to bots
well okay i'd rewrite cause i need partials lol
but like are display the images in a grid and they get resized before being displayed
if its like a background image for use in canvas or whatever, and that is used many times, cache it in memory. if its only accessed here and there by very specific commands, put it on the disk
Resizing them takes a while and the app is starting to lag when scrolling
so I was gonna cache the resized images and only resize if the cache version isn't available
if its a browser/client side thing, its always better to put it in the memory
unless its a very heavy app that takes hundreds of mb
@grizzled raven i rewrote to v12 while thinking about sharding as well
but in the end i went for internal sharding
my biggest concern was caching tho, because discord.js sucks at it
so i spent months dealing with that
were there any problems, that i would have to look out for when i do it or nah
depends how you want to scale it
traditional discord.js bots require tons of ram, which i wasnt willing to pay for
i'd switch to djs-light but then i would have needed to fetch the users of a reaction all the time
starboard bot lol
because i've heard that count could be unreliable
never actually tested - i was going to - but tonkku said it wasnt correct
i'll see for myself though
yes count can be unreliable, its better to count it yourself
ie: fetch the messge, fetch message reactions, store message id with count, update it with reactionadd/reactionremove
but then if the message gets uncached
ok see i have it where people can star the starboard message too, kinda like luca i guess
so then if the message gets uncached and starboard message gets another star, i'd fetch the reaction of the original message
after you store a message once in your database, you dont need to fetch it again, except on bot start to confirm its initial number of reactions
i mean, thats probably how i would do it
ok the real reason i do it anyway is because i dont have partials yet
but
if someone reacts on a message that's not in channel.messages but the message is still in a seperate collection, does the reaction count change?
the message shouldnt be in a separate collection
in my own collection
hmm good question, if the message gets stored as a reference, it will update
objects are usually linked as references by default
but you dont need to store the entire message object in your collection
you can store only the data you need
then would it not be a reference then?
the message isnt in any database (yet), so wouldnt i be better off storing the whole object?
or nah
i would only store ids
so you think i should fetch the message whenever i wanna get its properties?
i think im going to stick with storing the message as a whole, so i wouldnt confuse myself or ruin any caching but i wanna see your take on it
what properties would you need and when?
for the embeds i would create about with that message
but you only need it after X stars no?
how can i get where an error originated from without the stack
aka
im trying to catch an error
users can make it go to the starboard at whatever count they want
and i want to know where its from without printing the whole stack and just the 1 file it actually came from and the line number
so from 1-30
i would still do it that way
on reaction add -> if reaction === star -> add count to message id in database, if no message id create message id in database
if message id count > threshold -> fetch message and repost on startboard
hm
@knotty steeple you kinda do need the stack for that
thonkdead
i always check stuff with the message object though, i could make a little object containing what i need
is there any loss with caching the whole message?
@knotty steeple you can catch the error, and process the stack yourself
thats pain
// promise example
promise.catch(e => {
if(e.stack) {
let text = e.stack.toString().split("\n");
console.log(text[0])
}
})```
something like that
oh ok cool
wouldnt that be the message?
@grizzled raven its basically just how much ram you wanna waste with it
error.stack, isnt that like ```js
Error: you suck lol
at Client.emit.message("whatever")
so then wouldnt [0] be referenceerror: bla is not defined?
well either way, it doesnt matter to me i guess
yup it would
im getting off track xd
i might just stick with what i'm doing and if i get big or need more ram i could try that
sure
any way to check who banned someone WHO
d.js 11.5
Also on guild ban
How can i log who banned and everything
you need to fetch the audit log
On guild ban event
i fetch audit and check the latest entry
is that okay?
i mean the latest ban entry ofc
@quartz kindle
something like that yeah
Uhhh
Not really a good idea to only check the last entry
On massive actions, if your bot is a bit delayed, it may fail
Or if Discordβs API drunk as usual
I usually take at least the last 3 entries
Or 2
never seen eri speak here
just check latest ban entry where target ban matches user that was banned, if that even exists
i've never used the audit log api lol
is having one collection with 2 million entries better than 20 collections with 100k entries?
because when numbers get high i sometimes wonder
they should be offloaded to a database way before they reach that high
i mean say with guilds or users
just stick with whats consistent
dont split the guilds collection into 20 collections for no reason
its a valid question, i know what you mean
but afaik there is little to no difference
okay 
having more collections will have more overhead, but its negligible
unless
you need to loop/find/scan over them
unless
then its better if they are split into something that can be targeted/indexed
okay
if you have an array with length 2 and you fetch the first entry - [0] - would it be the same as having an array with length 400 and fetching the 49th entry - [48]
or length 430k and feching the 70,099th entry
basically, does it matter how big an array is when you fetch an entry
xD
https://discord.js.org/#/docs/main/11.5.1/class/Guild?scrollTo=fetchAuditLogs
how can i use the options.user thingy here? sorry if this seems dumb
fetchAuditLogs({ user: UserResolvable });```
Thanks!
discord provides a color option that = 3447003 for example
how do i convert it to hex, ie. #ffffff
Bro databases are heard
there's no good tutorial
someone should make an easy module that does it 4 me :)
your use of the term database is extremely broad
there are many modules that do SQL, NoSQL, and other types of databases
Ooo wait this looks cool
A one-click database, no server required.
Anyone use it before?
@sick cloud https://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hexadecimal-in-javascript
awesome ty
If you have no experiences in database queries, I'd recommend sequelize
mongoose is easy to use
@earnest phoenix easyDB is an ephemeral database provider. That means that after some time, your database will be removed. By default, databases will stick around for 24 hours. If you make an account with us, the database will last for 72 hours. If you really want to keep it longer, you can upgrade your database to a persistent database for $5/month.
basically it'll get deleted
= not a persistent db
That thing is a scam
Or you can just screw the server databases and use local, such as sqlite
There's plenty of easy sqlite wrappers
idk how to do a DB anyway, I'n tryna find a good nosql one I can install with npm and someone got a tutorial on
π€·ββοΈ
Sequelize supports sqlite as a dialect
Mongo is nosql
mongo
Nah, gotta be npm sir
long story
π€·ββοΈ π€·ββοΈ
I'll try sqlite
It is npm tho
npm i mongodb
no
where are you hosting
I got an ovh vps, I just don't wanna install shit off of npm
in such case of a host like glitch/repl.it literally no db will work since you don't have write permissions on them
okay
Honestly if you have no clue what you're doing just use something as simple as keyv which requires like 2 lines to get started, persistent and local
why another server
Then your option is to either pay, or use a local database
My house has a server on fiberoptic that got like 50tb
good job
That's great
host your db on the same server as your bot/etc
quicker speed and no security concerns
Which db are you using
rethinkdb myself
I have a database with >200,000 total entries and it uses about 20-30mb storage
It has like a kb of data per day per user
Not much at all
π
dbs are really efficient and use little data
rn it's just writing to local jsons which is what I'm tryna fix rn because JSON databases are bad
so a DB would bring down the size?
yeah
π
Ok
And wont corrupt as easily
That's great, still poses a threat
Low risk or no risk i'd go for no
I heard they only corrupt if u write to them at the same time
so I just havent
but yeah, I want a DB anyway
the JSON "database" is getting huge
lol
Not forgetting to mention it's also extremely inefficient
Since you're constantly reading and writing to disk
With FS
YES
I HAVE WIFI BACK
EEEEEEEE
ok so
how would someone go by making command handler using classes as the command
does that make sense
yes
but actually
no
but im smart so yes π
basically you do the exact same thing as a normal command handler
except you do ```js
new (require("./pathtofilelol/destroybotcommand.js"))(args)
yes
except im putting all the stuff in the constructor
is that also ok or how ur supposed to actually do it
however you want
Does anyone know how to make console.log output to the console when using pm2 to host?
the same thing?
you can pass everything into the super constructor of the actual command class
yea how about in the actual class
cuz run being a function is ok but what about my aliases and stuff
const Command = require("../Command.js") // Command base class
class Ping extends Command {
constructor(client) {
super(client, {
name: "ping",
aliases: ["pong", "p"]
})
}
}
something like that
then
that is how I do it
class pingCommand extends Terano.Command {
constructor() {
super({
name: "ping",
memberName: "Ping",
description: "Find out my ping",
usage: "ping",
silent: true,
cooldown: 0
});
}
}```
but then whats command base
I also have an
async run (message, args, data) {
//stuff
}```
command base is annoying
class Command {
constructor(client, data) {
this.client = client
this.name = data.name
this.aliases = data.aliases
}
}
oh yea makes sense
does passing client make any sense? because it would be client from start
depends on what you want
Does anyone know how to make console.log output to the console when using pm2 to host as a daemonized process?
in my first codeblock i passed client so then the super could define this.client
when I do node index.js if I have more than 4 apps infront of my command window it doesnt accept commands
I dont because client.user could change and message.client is already defined
so no reason to waste
pm2 has its own logs, do pm2 logs [id] to see them
^
np
and im pretty sure if client.user changes the command will change aswell as its a reference to the original object?
idk ask tim
Tim would know
or
we can try it
this is gonna break like all of my commands for a few mins
I dont understand
i think its because the object is only stored in one place in ram, and to get the object anywhere, it would reference that one place in the ram
bad
Are you asking your own separate question, or asking a question to a question?
what
Caches are used when something returns a collection of common items for instance; members, guilds, channels but not the singular. message.channel.name, message.guild.channels.cache.size.
(node:11051) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message```Can someone help? I'm getting this for the code:
```js
if (command === "readuser") {
if (message.author.id !== config.ownerID) {
message.channel.send(NL3Embed);
} else if (message.author.id === config.ownerID) {
const user = client.users.fetch(args[0])
message.channel.send(user.username);
}
}
I've already defined NL3Embed, don't worry about taht
It could be that it is not finding the user you are trying to find, maybe try this to verify the user exists before sending their username
if(user) message.channel.send(user.username);
then maybe it is something to do with NL3Embed
NL3Embed is completely fine, the other ones that uses the same embed works just fine.
Besides, it's not calling NL3Embed at all since the condition```js
if (message.author.id === config.ownerID)
hmm, im not sure
Oh i think I got it. You need to wait until you get the user until you can send it, so you should add await to it
const user = await client.users.fetch(args[0])
message.channel.send(user.username);
Okay, thanks
I have no idea
Though, this would probably work
channel.fetchMessage(lastmsg).then(msg => msg.delete());
sorry, i mean js channel.message.fetch(lastmsg).then(msg => msg.delete());
@neat gazelle
do i need to do message.channel since its in the event of a message?
<Channel>.messages.fetch("id").then(delete code here)
There is an easier way.
<Channel>.messages.delete(resolved message object)
let userID = message.channel.topic.split(" ");
let userFetch = message.client.users.cache.get(userID[0]);
let messageFetch = channel.messages.fetch(userID[1]);
let messagePop = messageFetch.split(" ").pop();
messageFetch.edit(messagePop);
TypeError: Cannot read property 'split' of null
help me out here. lol
userID[1] is the message id
You're going to have to give some context as looking at the code I kinda want to smash my head. βοΈ
You use the topic to store id?
maybe add await?
let messageFetch = await message.channel.messages.fetch(userID[1]);
basically trying to fetch the message by its id then edit the message with the same one without the last word
After reading the docs fetch on messages might be the wrong thing to use.
what the fuck
if you want to persistently store data
use a database
it's what they are for
?
does it know what channel is defined as on line 3?
bc you might have to do message.channel.messages.fetch(userID[1]);
let userID = message.channel.topic.split(" ");
let userFetch = message.client.users.cache.get(userID[0]);
let messageFetch = channel.messages.fetch(userID[1]);
let messagePop = messageFetch.split(" ").pop();
messageFetch.edit(messagePop);
TypeError: Cannot read property 'split' of null
still the same
What are you trying to split?
The content?
messageFetch.content.split
It fetches a message and returns a message object
the content of the message so i can pop the last value
does it say if the error is on line 1 or 4
Try the messageFetch.content.split
As pretty sure it's that and if it's not that would be an error later.
line 1
Use the console instead.
It's more useful as it's right with you.
Log message.channel
See what you get
lol i was typing in the wrong channel one sec
let userID = message.channel.topic.split(" ");
let userFetch = message.client.users.cache.get(userID[0]);
let messageFetch = channel.messages.fetch(userID[1]);
let messagePop = messageFetch.split(" ").pop();
messageFetch.edit(messagePop);
TypeError: messageFetch.split is not a function
let userID = message.channel.topic.split(" ");
let userFetch = message.client.users.cache.get(userID[0]);
let messageFetch = channel.messages.fetch(userID[1]);
let messagePop = messageFetch.split(" ").pop();
messageFetch.edit(messagePop);
TypeError: Cannot read property 'split' of undefined
line 4
TypeError: Cannot read property 'split' of undefined```
maybe add await?
let messageFetch = await message.channel.messages.fetch(userID[1]);
@hollow granite
its not in a async funtion tho
how lol
use async
Add async before the function keyword.
async function myFunction() {//code}
Or if you use a lambda async () =>
But first, might be good learning basic js. As it will help a lot.
Or re-learn.
JS arrow function not lambda
one sec
async function myFunction() {
let userID = message.channel.topic.split(" ");
let userFetch = message.client.users.cache.get(userID[0]);
let messageFetch = await channel.messages.fetch(userID[1]);
let messagePop = messageFetch.split(" ").pop();
messageFetch.edit(messagePop);
}
myFunction();
node_modules\discord.js\src\rest\RequestHandler.js:170:25```
@warm marsh @hollow granite
The error is self explanatory
Fetch takes fetch query options
Read the docs for understanding
d.js docs?
Scroll to fetch
Message wasnt found so the id is incorrect
but it is correct. so hold on my bad. the message that its fetching by its id is actually in a different channel. is that the problem here?
@warm marsh
Yes
If channel doesn't equal the channel that you're fetching the message from
The variable channel
Not the channel you're getting the id from
do i need to make a new variable getting the channel that the message is in then doing variable.messages.fetch??
No
on line 4
Just make sure channel is equal to a resolved channel
The channel being the one with the message in
but its always going to be in 2 different channels.
Then resolve it by using fetch
const chan = message.guild.channels.fetch(chanid)
chan being the channel variable
so then do
let messageFetch = await chan.messages.fetch(userID[1]);
Yes
aight one sec
async function myFunction() {
let userID = message.channel.topic.split(" ");
let userFetch = message.client.users.cache.get(userID[0]);
let channelFetch = message.guild.channels.fetch('694833153617166438');
let messageFetch = await channelFetch.messages.fetch(userID[1]);
let messagePop = messageFetch.split(" ").pop();
messageFetch.edit(messagePop);
}
myFunction();
(node:14056) UnhandledPromiseRejectionWarning: TypeError: message.guild.channels.fetch is not a function
Check the docs, I'm going to head to bed. Good luck.
thanks for you help tho. im pretty close now because of you
Always console.log paint Leave ????
serverQueue.songs[0].url how do i cut the id https://www.youtube.com/watch?v=RKW6rjnYEkc
RKW6rjnYEkc
@warm marsh i was able to figure it out now. thanks for the help
You could use the slice method with a negative number https://www.w3schools.com/jsref/jsref_slice_string.asp
k thx
const serverQueue = message.client.queue.get(message.guild.id);
const vurl = serverQueue.songs[0].url;
const vidid = vurl.split("https://www.youtube.com/watch?v=");```is this right ?
k
Wait no
@earnest phoenix
If server Queue.songs[0] is already defined, serverQueue.songs[0].id should exists
How do u define song
song = {
title: songInfo.title,
url: songInfo.video_url,
duration: songInfo.length_seconds,
vidid: songInfo.video_id```
vidid is already defined
const song = {
id: video.id || video.video_id,
title: video.title,
url: video.video_url || "https://www.youtube.com/watch?v=" + video.id,
duration: `${minute}:${seconds}`,
author: {
id: message.author.id,
username: message.author.username
}
} ```
Like thzt
hmmm
https://lumap.is-inside.me/eSm3kfIA.png excuse me wtf
why vote is marked unused
weird
hmmmmmmmmmmmmmm
oh
π
when I make an anti spam feature, what would I need to put in the anti_spam define for python?
I assume you want a dictionary
pretty much
There has been some issues...
(node:163) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: SQLITE_IOERR: disk I/O error
```help?
Code? @earnest phoenix
Hmm...
I think after using ```js
message.guild.owner
Something like this :
```js
message.guild.owner.tag
```? If that's not the issue, then I have no idea.
Or maybe actually you didn't have the message.guild.owner cached
Maybe you should fetch it first, idk.
hey my bot is listed as offline while still being online this only happens when i daemonize the node file is there something iβm doing wrong
If it was offline for a while, it might have been shown as offline. Just wait, and the website should update it after some time.
well has been online for an hour but it only shows that itβs online when someone interacts with the bot
isnt that like
the purpose of daemon threads?
they run in the background using as little as possible reasources
then when somthing happens that it actually needs todo loads up and does stuff
yeah thatβs the reason that i daemonized it
TypeError: Cannot read property 'execute' of undefined
```Can someone tell me what happened?
if (!message.guild || message.channel.type === "dm" || message.author.bot || message.author === client.user || message.webhookID)
return;
if (message.content.toLowerCase().startsWith(config.prefix)) { //I'm using config.json to store my prefix
const commandName = message.content.slice(config.prefix.length).toLowerCase().split(" ")[0].toLowerCase(); //k
const args = message.content.slice(config.prefix.length).split(" ").slice(1);
const command = client.commands.get(commandName);
try {
await command.execute(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed);
} catch (err) {
console.log(err);
}
}
return;
//Locator and Link + Configuration
const fs = require("fs");
const Discord = require("discord.js");
const client = new Discord.Client();
require("dotenv").config();
const config = require("./config.json");
var eco = require("discord-economy");
var leveling = require("discord-leveling");
var db = require ("./db.json")
//Important Embed Pieces
var avatarURL =
"https://cdn.discordapp.com/avatars/683597011693469698/d9733c732d874e5137a9738b21d54acd.webp";
var footer = "Β©Mineko | v1.5.2 Beta | 31 Loaded Commands";
var clientname = "Mineko";
//Other Variables
if (client.guilds.cache.size === 0) {
var clientactivityset = `Booting up System... ${footer}`;
} else if (client.users.cache.size === 0) {
var clientactivityset = `Booting up System... ${footer}`;
} else {
var clientactivityset = `)help | ${client.guilds.cache.size} guilds | ${client.users.cache.size} total users`;
}
//Command Ban Embed
const NL3Embed = new Discord.MessageEmbed()
.setAuthor(`${clientname}`, `${avatarURL}`)
.setColor([173, 216, 230])
.setDescription("Command restricted to Developers only.")
.setFooter(`${footer}`, `${avatarURL}`);
//Dev-Lock Embed
const DevEmbed = new Discord.MessageEmbed()
.setAuthor(`${clientname}`, `${avatarURL}`)
.setColor([173, 216, 230])
.setDescription(
"This Command is still under development, it will be available soon."
)
.setFooter(`${footer}`, `${avatarURL}`);
module.exports = {
name: "say", //command name
async execute(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed) {
///Command Starts Here
if (message.author.id !== config.ownerID) {
message.channel.send(NL3Embed);
} else if (message.author.id === config.ownerID) {
if (isNaN(args[0])) {
var user = message.mentions.users.first();
if (!user) {
var user = message.author;
}
} else {
var user = await client.users.fetch(args[0]);
}
var amount = args[1];
var cmdusage =
"Please use `" + `${config.prefix}` + "give` `<user>` `<amount>`";
if (amount < 0) {
return message.reply("That's subtracting!");
} else if (isNaN(amount)) {
message.channel.send("That's not a valid Number!");
} else if (!user) {
return message.reply(`${cmdusage}`);
} else if (!amount) {
return message.reply(`${cmdusage}`);
} else {
var output = await eco.AddToBalance(user.id, amount);
message.channel.send(
`${message.author} gave ${amount} to ${user}. Newbalance : ${output.oldbalance} >> ${output.newbalance}`
);
}
}
}
}
await command.execute(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed);
TypeError: Cannot read property 'execute' of undefined
Yes
why did you give all that code
IDk, i felt like it was needed
you just have a probleme with your function
you just have a probleme with your function
@twin iron Where?
in the last code clock
Which piece did i miss?
async function execute(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed) {
use that instead async execute(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed) {
umm, okay..?
wait
async function execute(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed) {
^^^^^^^
SyntaxError: Unexpected identifier
the last codeblock is just a normal command right
ah no sorry its a method
Yes
then the first is how you run your commands?
Yes
maybe it cant get the command then for some reason
Also, I would like to point out that my other commands are just fine
When it loads, no error, but when i execute it, it comes out as an error
what
oh and there is a bunch of stuff u should actually not be doing
beside that
why do you pass all of those args
var eco = require("discord-economy");
var leveling = require("discord-leveling");
var db = require ("./db.json")
var
goddamn var
and a json database


and a json database
@knotty steeple Static Database
I use sqlite
also discord-economy
it isnt that hard to handle economy yourself
Which i played with like hek
it isnt that hard to handle economy yourself
@knotty steeple I didn't know, I'm a nub
@high bough module.exports = {
name: "say",
execute: async function(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed) {
...
}
}
js is weird with its errors
No π€
@high bough module.exports = {
name: "say",
execute: async function(client, message, args, Discord, config, eco, leveling, db, avatarURL, footer, clientname, NL3Embed, DevEmbed) {
...
}
}
@white gate I fixed it already
It was that the command is addbalance but the name was say
Hey. Does anyone know in what way collections like client.channels and client.guilds are ordered? (Discord JS)
the default
I did not order it
By default it's generally ID
check it out yourself
but I checked it, well let's do it again
ohh well I see it now
it's ordered like this:
-first made channel
-second made channel
- ...
second guild it joined
-first made channel
-second made channel
- ...
last guild it joined
-first made channel
-second made channel
- ...```
[python]anyone have any idea how to fix this error?
[Errno 2] No such file or directory
#this function gets a file full of number from one to n, not sorted, but one of the numbers are missing, suppose to find the number, add it to another file and return it.
# file_name tpye - str
def who_is_missing(file_name):
fille = open(file_name, 'r')
string = fille.read()
string.replace(',', '')
my_list = list(string)
fille.close()
my_list.sort()
for x in range(0, len(my_list)):
my_list[x] = int(my_list[x])
num = my_list[-1]*(my_list[-1] + my_list[0]) / 2 - sum(my_list)
new_file = open("found.txt", 'w')
new_file.write(str(int((num))))
new_file.close()
return int(num)
print(who_is_missing(r"D:\codes\nums.txt"))
and yes, this file exist, i didnt just put a random path
How do I get out of Discord v12 and go to v11? which command on the console?
npm i discord.js@11.6.3
Thanks
Hi i am using latest ytdl-core version and i am trying to optimize my code for memory usage . I want to clean buffer of the stream data. How can i do that ?
i am using node.js
if you are storing a buffer in a variable/array/object, you can simply rewrite the value to null
if you're using streams directly, make sure they are not stored in any persistent variable after they end
anything that is not stored or referenced in a persistent variable outside of the scope, will be garbage collected automatically
Is it valid in Ytdl or only in my code?
heroku is built for python
Hey, what's wrong? :v
wait... has there never been client.roles in Discord JS? (because guild.roles and client.channels both do exist)
@narrow kettle print(who_is_missing(r"D:\codes\nums.txt"))
Is that "r" supposed to be there?
ah
but he already used the "r" here: fille = open(file_name, 'r')
after the method is called it'll be: fille = open(r"D:\codes\nums.txt", 'r')
Python raw string treats backslash (\) as a literal character.
wait... has there never been client.roles in Discord JS? (because guild.roles and client.channels both do exist)
@nocturne grove yeah that's never been a thing.
oh lol. Thanks for answering
What does it mean for a field to be "inline"?
@lyric mountain im pretty late with answering but i gotta use it else it gives me an error
How do I properly fetch a member from an id?
What version

