#development
1 messages ยท Page 1128 of 1
ok
so
its working
but
the server value is still 0 even though its in 2 servers
@toxic bane https://lmgtfy.com/?q=meme+api
@nimble escarp thanks!!
For all those people who find it more convenient to bother you with their question rather than search it for themselves.
hi
hi
because you're defining it outside the ready event, as i told you before
Could you just send it like a normal message next time so that other's questions don't get pushed up too fast? @eternal flame
im not picking up what youre saying here tim
ill just give you the code block that i think is giving me the issues
it is but
ok here
``let stats;
bot.on("ready", () => {
console.log('api boy is on')
stats = {
"rainbow": 5,
"unicorn": 3,
"doom": -3,
"gloom": -2,
"poopoo": 2,
"servers": servers
}
})``
yes
Ask your code @earnest phoenix
@eternal flame as i said, you're defining the variable servers before the bot is ready, so the servers will always be 0
how do i fix that
isnt it obvious?
@earnest phoenix return if author is a bot
You are not checking if the sender is a bot
@earnest phoenix make it ignore bots
if (!message.content.startsWith(this.prefix) || message.author.bot) return;
This is what I use normally
Thanks for flooding btw
ok tim
so
it worked
but
it says 5 servers
and its in 2
wait let me check
imagine tho lol
ok brb
So... I'm trying to figure out this issue I got. I think it corrupted my json db.
I suspect someone had a weird unicode username that didn't serialize well
It was recently wiped
ok so
either wipe it again or look at position 12248 for some unclosed string
im gonna wait for auger to finish cuz i dont wanna be a dick
although it might be that the file was incorrectly truncated, so the problem might not be a broken string, but a whole chunk of data being cut off
@dreamy elm did you start the server yet
well timo it wont show nothing
bc nginx is masking the ip to a port
although it might be that the file was incorrectly truncated, so the problem might not be a broken string, but a whole chunk of data being cut off
@quartz kindle It overwrote the json file back to empty on that error because the file size dropped way down
I need to get my SQL db context working
So I can hurry up and mirate
bc nginx is masking the ip to a port
@twilit rapids
ok so using graingers code that he gave me (props to him) i figured out that the 5 servers things WASNT an issue and that it was just me being a fucking idiot
so
how can i find
the number of members
like
total
how many members are in each server the bot is in
combined
oh snap, I had a backup
use a reduce function on the guild cache, do yo know how to use a reduce function?
I'm exploring MongoDb. My DB class is essentially a List<UserRecord>
Is this what the DB should look like? I just threw my Json db at it
Or is there a way to make the _id the UserId, or primary key, or something like that
i do not tim
you probably want each user record to have a unique id so it can be properly indexed
Also, telling me to google is an acceptable reply lol
Yeah, the record's ID is <ulong> UserId
I'd like this to be the PK
are you using a collection?
I'm exploring MongoDb. My DB class is essentially a List<UserRecord>
Is this what the DB should look like? I just threw my Json db at it
@quartz kindle
i mean, if you did anything with mongodb collections
like db.someCollection.insert()
or how did you transfer from json to mongo
Let me show you my user record repository class
That's essentially my JSON database
Nothing fancy
mhm
did you actually write to mongodb yet?
No, I imported via JSON file just to test it out. I'm assuming that doesn't make for the cleanest db.. ๐
ah
i dont know what mongo does when importing json, but from the image you sent before, it doesnt look right
how do i check to see how many members are in all the servers my bot is in combined
But, I think dropping the UserRecordsRepoitory would make it convert better.
That collection was not indexed
i'd look into creating a collection in mongo db, then iterating over your json users and inserting each one into the collection, using the user id as the _id field
usually each document has its own _id for indexing
ye, it should be a collection with each user as a document
I believe getting by _id is much faster than by other properties
because it's guaranteed to be unique
@eternal flame guilds have a .memberCount property
which gives you the total number of members it has
but to combine the memberCount of all guilds, the easiest way is to use a reduce function
a reduce function takes a list of items, for example an array, and does something with all of them until there is a single value left
for example ```js
array = [1,2,3,4,5];
result = array.reduce((previousValue,currentValue) => previousValue + currentValue, startingValue = 0)
result // 1 + 2 + 3 + 4 + 5 = 15
so basically
its a very complicated way of saying 1 + 2 + 3 + 4 + 5 equals 15
or so and so + so and so + so and so + so and so + so and so + so and so = dsjlghfekhdhfdgs
exactly
ok so
its a fast way to reduce any number of items into a single value based on whatever function you want
i have my bot set to log what servers its in and how many members each server has but it does not combine them
(thans grainger for the code)
ill show you
it console logs
"server is starting" is just a bug
you know how to get the number of guilds, right?
does anyone wanna say their opinions on the website I made? I'm looking for feedback it's my third ever website
so to get the number of guilds, you use client.guilds.cache.size
yep
client.guilds.cache is an instance of a Map object, which is how discord.js stores guilds
you can read more about Maps here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
dora the explorer intensifies
but discord.js takes the default Maps and extends them with new functions
alr
many of the array functions are added to them by discord.js
including a reduce function
so you can directly do client.guilds.cache.reduce()
shut up
rly?
thats a lot easier then i thought
so wait
how would i
wait
how would i have that display as a number
their reduce function is nearly identical to the original reduce function that arrays have, you can check the original reduce here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
so if you learn how reduce works in one, you can use it in the other exactly the same way
hm
how would i log this to the console
i just tried console.log(client.guilds.cache.reduce()) and that didnt work
(of)
ofc*
what would the function be
remember the example i showed you above?
wait
hold on
would it be
i dont wanna fuck up and sound stupid
function
client.
hot or cold
cold
do you know how to use .find and .filter and other array functions?
in my dreams maybe but thats the highest chance
Trying to figure out which one of these fits a ulong
64-bit (8-byte) integers is what I need
probably long
wouldn't it being an unsigned long have an issue with that?
which app is that?
MongoDB Compass
ok so it does start with function right
Long would make a ulong truncate. Unless it was a long long
cant find anything in the compass docs
me either :/
decimal128 would probably be long long
I'll look more into that db, but I don't need percision..
so number would be uint32, and long would be uint64 i believe
but they have a separate int32
u guys sound like me trying to figure out the difference between 32 bit and 64 bit
trying to figure out what exactly mongodb compass means with those names lol
anyway, you never used .find() or .filter()?
no
Decimal128 supports 34 decimal digits of significand and an exponent range of โ6143 to +6144
you never used any array function?
nae
what about forEach
Do you know what an array is?
ok so, when you do something.forEach() inside the forEach you put a function
and the function is executed once for every item
this function is given the current item, for you to do something with it
for example
["command"].forEach((handler) => {
require(./handlers/${handler})(bot);
}); are my cmd handlers
something.forEach(item => do something with item)
OHHH
oh
so
would the
the the the
the do something with item
be the reduce function
and the item
be the server count
or
more or less
if you wanted to do .find or .filter, it would be the same thing: something.filter(currentItem => do something with current item) or something.find(currentItem => do soemthing with current item)
but with .reduce its a bit different
with forEach, find and filter, you function is given the current item, to do something with it, but with a reduce, the current item is given as the second parameter, not the first
the first parameter is an accumulator, which holds the total combined value so far
oh
so a reduce would be like this
something.reduce((accumulator,currentItem) => do something with current item and accumulator)
what would it be with the needed things replaced with things to get member value
ListOfThing.ForEach(aThing => aThing.thingsProperty = newValueForThing) // Replaces every things property
what does he want to do
the accumulator has no initial value, it starts as being undefined, but, the reduce function gives you an option to set an initial value, as the second parameter
yeah you can just use array.reduce
so for example
we want the final value to be a number
so lets set the accumulator's initial value to 0
something.reduce((accumulator, currentItem) => do something, 0) <-- 0 is the initial value of the accumulator
so let me get started on this
kinda
if
i set the amount of servers its in as servers
would it be
["servers"].dbjsfgkjdsgfd.g(dfskjgkhfdhgdfsgf)
no
hm
anyway, the do something part, its basically, what to do with the current item, and the accumulator, and whatever the result is, the accumulator becomes that result
for example, if you put accumulator + currentItem in the do something part, then if accumulator is 0 and item is 5, then the accumulator becomes 5. so when the next item comes, let say the next item is 6, the next step will be 5 + 6, and the accumulator becomes 11, so the third item comes, lets say its 10, it will do 11 + 10, and the value will become 21
exactly
its like im learning math all over again lol
im just gonna call you mrs. baily now
jk
ok but
so to do this with guilds
when you do client.guilds.cache.reduce((accumulator, item) => do something, 0)
the item, is a guild
not a number
but the guild contains a .memberCount property
which is what we want
so you simply do accumulator + item.memberCount
wait
so
client.guilds.cache.reduce((accumulator, membercount) => do something, 0)
oer
or*
wiat nop
wait no
servers would go there right?
client.guilds.cache.reduce((accumulator, servers) => do something, 0)
it doesnt matter what you write there, its just a name
oh
the item is always going to be a guild
because you're doing reduce on the guilds.cache
ok
so
client.guilds.cache.reduce((accumulator, servers) => do something, 0)
what would
go into the do something
in the above case, servers would be 1 guild
the current guild being done something do
and all guilds have a .memberCount property
so
wait
so we
go through each guild individually
get the member count
add that to the acc.
and then
exactly
oh
would that just be
like
client.guilds.cache.size = servers
client.guilds.cache.reduce((accumulator, servers) => do something, 0)
nope
ASJKGHGUFSDKHJKHFDDJSFF
you dont need servers at all
wait
whatever you write in there
what?
ok
hm
ok so im gonna put servers in there for now
where do we determine the amount of guilds to go through
or does it
determine that auto.
oh
ok
so
client.guilds.cache.reduce((accumulator, servers) => do something, 0)
the accumulator
would be 0 right
yes
no

the beginning of the function is where you define the names
it doesnt matter what you write
wait so
could be (accumulator, item) => or (a,b) =>
is
its just a placeholder name

what matters is how you use it inside the do something part
client.guilds.cache.reduce((accumulator, servers) => do something, 0)
we have this so far
client.guilds.cache.reduce((accumulator, servers) => a complicated way of saying add it all, right?, 0)
more like, an easy way of saying add the current item to the accumulator
<What does that 0 at the end doing there>
the initial value
client.guilds.cache.reduce((accumulator, servers) => current item?,0)
that will make the accumulator become the item
shit
almost there
client.guilds.cache.reduce((accumulator, servers) => servers, accumulator, 0)
omg
wait
client.guilds.cache.reduce((accumulator, servers) => servers + acc?, 0)
yes
but still theres something missing

because the current item is a guild, not a number
they types dont match, they cant be added together
you want to get the memberCount from it
where would membercount go
memberCount is a property of guild
if a = guild then memberCount would be a.memberCount
where would that goooo
client.guilds.cache.reduce((accumulator, servers) => servers + a.membercount?, 0)
you named your guild servers not a
dshigbgdfjkhkjgdfl
client.guilds.cache.reduce((accumulator, servers) => servers + servers.membercount?, 0)
now you removed the accumulator
h
client.guilds.cache.reduce((accumulator, servers) => servers + a.servers.membercount?, 0)
Bruh
put the accumulator back
Bruh
client.guilds.cache.reduce((accumulator, servers) => servers + a.servers.membercount?, accumulator, 0)
lmao
hh
this is painful and fun to watch
you were almost there, now you're fucking it all up
TAKE A STEP BACK
Just do a fuck go back
client.guilds.cache.reduce((accumulator, servers) => servers + acc, 0)
yes
And add memberCount property to both
not both
not both
Nani
now is just the stage where you move something around till it works
accumulator will be a number
LOL
servers is the item itself, right?
client.guilds.cache.reduce((accumulator, servers) => servers + acc, something here, 0)
servers is one guild
Nope
no commas
f
Hello everyone, tell me do you know how we can do to see the number of servers in which our bot is (mentioned me if you knew please)?
leave the commas as they are
client.guilds.cache.reduce((accumulator, servers) => servers + acc, something here 0)
@earnest phoenix
<Client>.guilds.cache.size```
leave the 0 as it is
so remove soemthing here
@earnest phoenix good ^^
no
f
i said everything else is correct
Remove sumthin
take a step back, i must
client.guilds.cache.reduce((accumulator, servers) => servers + acc, 0)
is what i have
yes
like i said
that is correct, the only problem is that servers is a guild, and accumulator is a number
You'd need to edit the servers that's after =>
this is the stage where you move shit around until you get lucky and it works
noop
but because servers is a guild, it has a .memberCount property you can access
There's no need to move shit around

so how do you get the member count from a guild?

guild.memberCount
Yes
exactly
Almost
SHIVACO I HATE YOU
Well, it's not literally guild
now your guild is called servers because you gave it that name
so what do you have to do?
servers.memberCount
bingo
jhk;fgdbajklo;fgdbajlkbf;dsfgdsjkl;
Yes
client.guilds.cache.reduce((accumulator, servers) => servers + acc, 0)
so
we take
servers.memberCount
and put it
where
inside the => ,
replace servers with it or keep everything and just do servers.memberCount + etc + etc, 0
replace servers with it
client.guilds.cache.reduce((accumulator, servers) => servers.memberCount + acc, 0)
Yes
sweating
You can name it a
Lol
Lmao
uh
okay
i feel like
i should think about what to name it
like its my newborn child
client.guilds.cache.reduce((steven, servers) => servers + acc, 0)
Learning time with tim
client.guilds.cache.reduce((hoarder, servers) => servers.memberCount + servers + hoarder, 0)
why the extra servers
oh
You don't need the servers +
client.guilds.cache.reduce((hoarder, servers) => servers.memberCount + hoarder, 0)
Yes
yes very good
now you can give all of that to a variable
so
let totalMembers = all of that
var piece_of_shit_that_took_me_an_hour = client.guilds.cache.reduce((hoarder, servers) => servers.memberCount + hoarder, 0)
yup
alr
Yes lol
Yea, lmao
I'll kindly yell at you for using snake case in JS
Now tim
What_About_This
Teach me all of react in 10 seconds
i cant beliebe i just spent an hour on this
Well you're permamuted now Tim
missing a comma
yes
you forgot a comma after- eh fuck phone
Who doesnt do that
so you have to adapt
nice

Tim
Whats the domain? @eternal flame
@honest perch i dont know react >.>
localhost moment ๐ณ
How can we make sure Tim really isn't the creator of javascript
i still need to port the thingy
Who doesnt do that
@honest perch
i do i named my client, client

iim just working on getting it set up rn
iim making an api
I name it "thisisjustelectronbutdiscordversionsoramgobrrrr"
wait really
@quartz kindle It auto changed to a double
Weird. The website has Int64, but the Compass client doesn't
Who uses 64
People with ulongs
storing IDs as strings gang
No way
but isnt double supposed to be for decimals? doesnt make sense to use double for ints
Yeah, idk
i tried compass once and didnt like it
tbh i didnt like any of mongo
i prefer sqlite
Depends on preference
I heard PostgreSQL is very efficient compared to the rest
but I like mongo because it's NoSQL and I just like fucking my JSONs up
there are pros and const to both styles
nosql received a lot of hype but people are kinda finding out its not that great after all
the popularity of sql is going up again
I mean, I don't use NoSQL for its popularity really
And I kind of see why it's that way
anyone know how to use style on top.gg ?
it seems that css is not working
i'm trying to use style on this part of the site
to change the white color to another
you login to your router
i mean i got it successfully forwarded
but
its not
accessable
from anywhere else
aand idk what to do
its still a local boy
Firewall
you need router id and password as far as i know
if you managed to set a port forward from your router pannel
Happy cake day shiv
then you have to go to firewall and make sure that the specific program has allowed traffic trough your firewall
wait
so
i go off of att interne
an im using port 3000
for an api
is that
a good thing
i think you can go with any port, if it's not used by something else
ok so
its still
its stuck on local still
uh
its not
public
im using a rasp pi and it wotn let me in
check firewall settings
get your ip from https://whatsmyip.org
Your IP Address plus Port Scanners, Traceroute, HTTP Compression Test, Ping, Whois, DNS, IP Geo Location, Password Generator and many more tools and how-to's
dont post it here though lmao
btw keep it one message
prob good idea
what model do you have?
if you don't have access to your router's settings, then you're pretty much at a dead immediately
css
BGW210-700
<style> tags on your long description
i have access to the router stuff
Port forwarding is used to access devices on your home network from outside your home. Learn more about port forwarding and set up for your gateway.
i did something like
<style type="text/css">
.class1 {
}
</style>
<body>
<p class=class1> test </p>
</body>
and it's not working
https
f
i did something like
<style type="text/css"> .class1 { } </style> <body> <p class=class1> test </p> </body>and it's not working
@gray finch use <style> only, not <style type="text/css">
yeah
ok , but how do i get buttons class name, to customize them
inspect element
big brain
tcp/udp
big brain
@gray finch nah i'm fr, inspect element is the best way to go, it can give you all the class names for the buttons and stuff
https is tcp though
unda
this is one of the reasons why i don't host on windows
vps
whats that
hg vps
any
how VPS
where vps
vps that has fast latency
i want to
host an api
i mean
it can already grab the data
but
meh
fuck it
i want to make it so if the user has the role already and you say !role it removes it instead of adding the role
this is my code:
@client.command(pass_context=True) @commands.has_permissions(administrator=True) async def role(ctx, user: discord.Member, role: discord.Role): if role in roles: await user.remove_roles(role) else: await user.add_roles(role) await ctx.send(f"{user.name} has been given {role.name}")
yeah but instead of making a whole command on removing roles
i want to make it one command to remove and add roles
do you get me @rustic nova
if role in user.roles:
remove
else:
add

how i can unban in the event on_message? discordpy
unban whom
how do i make @command.cooldown convert to hours
await client.unban(message.guild, client.get_user_info(722594354576883762))
i made a daily command
if used collects coins once a day
and basically ahs a day cooldown
Well
you should probably store long term cooldowns in a database in case the process dies for whatever reason
discord.Object(id=your_needed_ID_here) to avoid an unnecessary API request
and use message.guild.unban without passing the guild again as an argument
uhhh
@slender thistle Hey tell me how do we get the Bot Developer rank?
dont work @faint prism
AttributeError: 'Client' object has no attribute 'unban'
So client is going to be your discord client object variable
@earnest phoenix #development message
Shiv probably knows more than me about this ^
Use message.guild.unban and pass it an instance of discord.Object
discord.Object(id=id_member)?
@slender thistle
ok and my bot gets tested when the shots?
id_member being ID of the member, yeah
thx
@earnest phoenix I'm not sure what you mean, but bot revies currently takes 3 weeks or more
wtf
What the fuck is that
Did you type something instead of when you meant to make it a string?
What's a command in python? lol
how do you even get that
It's just python(3) some_file.py so idk how they got that
magic of assumptions and there we go
is a stupid question but, how i can do a .then() in python?
Henloo, so I changed from hosting on glitch to locally hosting my bot but for some reason, even after installing all the packages required, im getting a MessageEmbed is not defined error when its a global variable in the file. I tried to use a different command that used embed and it worked. I'm using discord.js v12.
Here is where my code isnt working ( i removed the link bc well ouo )
and I would like to say that i didnt change anything in the code when i started hosting locally. It was working fine on glitch.
please @ me if someone answers thank you
@fleet hornet is there an error
@uneven estuary what discord.js version?
v12
doesnt work
Some things were changed about the MessageEmbed, correct me if i'm wrong
you're asking to be ddos'd
BGW210-700
just use some kind of tunnel
don't expose a port on your home ip lol
people will either fry your router or dox you
@fleet hornet does the embed send?
Some things were changed about the MessageEmbed, correct me if i'm wrong
@rustic novaim not sure but it was working fine on glitch
prob
better yet, don't even host locally, just get a vps
i have port 80 exposed uwu
ofc
@uneven estuary that's the only thing i remember back then, that RichEmbed was changed to MessageEmbed or smth
i have a feeling something else other than your logging code is causing the restart
that's the only thing i remember back then, that RichEmbed was changed to MessageEmbed or smth
@rustic nova yeah
would you mind showing the rest of your code
why not just debug and see what is actually going on instead of guessing
if you're running with the debugger in vsc for example
that doesn't do much if you don't have breakpoints
log at points and try catch
/ or place a brakepoint
breakpoint*
how do i send hi marked text in discor dpy
what have you tried
i want to make it so the bot sends marked text
what have you tried
well
**
**
-_-
have you tried actually using the same syntax as you do as an user
yes
which is a logic step in every normal humans brain
like sending **hi**
yeaah
my bad
i'm stupid -_-
you are.
Wow, gottem
are you sure about that
or that you don't have multiple instances turned on
the message that was deleted wasn't in cache, so it has no properties at all. when you delete a message, all discord gives is the message id in the event, nothing else, the libs pull other relevant data from cache
hm
`@client.command(aliases=['with'])
@commands.cooldown(1, 5, commands.BucketType.user)
async def withdraw(ctx,amount = None):
await open_account(ctx.author)
if amount == None:
await ctx.send("please enter the amount!")
return
bal = await update_bank(ctx.author)
amount = int(amount)
if amount>bal[1]:
await ctx.send("you don't have that much money!")
return
if amount<0:
await ctx.send("amount must be positive!")
return
await update_bank(ctx.author, amount,)
await update_bank(ctx.author, -1*amount, "bank")
await ctx.send(f'you withdrew {amount} coin(s)!')`
how do i make it so if i say .withdraw all, it takes everything out of the wallet. instead of typing the numbers you have in your wallet
There's the option of doing if amount == "all":
let votes = client.fetch("https://top.gg/api/bots/480421483575902208/votes", {headers: {Authorization: process.env.DBL}}).then(res => res.json())
.then(json => {
let voters = [... new Set(json.map(x => x.id))];
return voters.map(x => {
return {voter: x, count: json.filter(x => x.id == x).size}
})
}), numer = 0;
message.channel.send(
new client.Embed(message.guild.id)
.setTitle(`${message.guild.name} - Votes Leaderboard`)
.setDescription(
votes.length >= 1
? voters.map(top => `**${numer++}.** **${client.users.cache.get(top.voter).tag}** - **${top.count}** Vote${top.count == 1 ? "" : "s"}**`)
: "Nobody has voted yet!"
)
)
Why does this return the "Nobody has voted yet?"
wait im dumb
nvm
yeah it returns a promise
Stats should be a owner command or public command?
Depends what stats
Ram, cpu, users, server count
client.fetch("https://top.gg/api/bots/480421483575902208/votes", {headers: {Authorization: process.env.DBL}}).then(res => res.json())
.then(json => {
let voters = [...new Set(json.map(x => {return{voter: x.id, user: `${x.username}#${x.discriminator}`}}))], numer = 1
let votes = voters.map(x => {
return {voter: x.user, count: json.filter(y => y.id == x.voter).length}
}).filter(x => x.count != 0).sort((a,b) => a.count - b.count).slice(0, 10).reverse()
message.channel.send(
new client.Embed(message.guild.id)
.setTitle(`${message.guild.name} - Votes Leaderboard`)
.setDescription(
votes.length >= 1
? votes.map(top => `**${numer++}.** **${top.voter}** - **${top.count}** Vote${top.count == 1 ? "" : "s"}`)
: "Nobody has voted yet!"
)
)
})
Ok I got somewhere
https://i.callumdev.pw/0y7sp.png
Why are you even making a raw string to then be parsed into an object with Object?
nice
ya
well its sorta fixed
i am on it twice?
updated code block above
3 times actually
formatted would look like { "id": 10, "moreid": 4 }
so in the embed, you can use Object.entries(formatted) and map them however you like
great formatted https://i.callumdev.pw/6qkmg.png
nice
yours is done differently then
the votes are from the same endpoint, hmm
does anyone know how to fetch data from a JSON file in javascipt? i know how to use requests in python but i don't know how to convert it into javascript (btw im using https://api.thecatapi.com/v1/images/search and want to fetch "url" when a user types in a command in discord)
oh where did that come from
uh
you'd want to parse the json response
can't help, sorry
there should be plenty of tutorials online
okay
after some short time spent on google i know how to do actually most of the things except for grabbing the JSON file from the website
ah, can't you use the request module?
get the response from the API and parse it as JSON
i know var jsonFile = "{"name":"hi"}"
var ojb = JSON.parse(jsonFile)
consoel.log(ojb.name)
i cant figure out how to get jsonFile to be equal to https://api.thecatapi.com/v1/images/search
that's javascript
yes
was it too confusing?
i meant to say i know how to do it in python but i want it in javascript
sorry if i came across as confusing
oh haha
lmao, i do that too much
do you use a package for requesting?
wdym,
e.g. axios and node-fetch
i haven't actually gotten into any of these,
i got as far as the other thing, i don't know what package/how to use it
you should get one of those packages to make things easier
alr ill install node-fetch
good choice, i use node-fetch too
I want help in my website i wanted that if someone press a button in my website then it should then my discord bot should send a particular message in my server that this person have pressed this button i cant understand how to attach website with bot.
yes
an example in node-fetch would be const obj = await fetch("endpoint").then(x => x.json());
basically, it converts the response to a parsed object
you can access obj.url that way
how do i use node fetch? const fetch = require('node-fetch')
sure
sorry if i'm asking a lot of questions
aw thank you
anyways so after i get that fetch, const obj = await fetch( what is endpoint? https://api.thecatapi.com/v1/images/search ?
The button should send a request to an api that has acess to your bot @surreal notch
yeah, that's the endpoint
Which can then send a message in a channel
then parse obj, and then we're good?
I m actually noob in backend
mhmm
node-fetch is cool
also btw
if i do function(message) {
will that work with await or do i have to require async?
you'd want to add the async keyword, so async function(message)
that way you can use await
okay
@solemn latch and how the button can send a request
there's always .then but it might make your code look wonky
i m trying this first time
<role manager>.create in v12
role manager would be for example, message.guild.roles
ok
you should read docs though
you might have messed up the structure
let me send it
@surreal notch https://stackoverflow.com/a/16036129
ah, too lazy to send link
did I mess up?
what version are you on?
yes
cmd not found
oh, try npm ls discord.js
if(message.content == 'y!cat') {
const obj = await fetch("https://api.thecatapi.com/v1/images/search").then(x => x.json())
const catURL = JSON.parse(obj)
const catEmbed = new Discord.MessageEmbed()
.setColor('0dff00')
.setTitle('Meow!')
.setImage(catURL.url)
message.channel.send({embed:catEmbed})
}
you don't need to parse it agian, it's already json
you don't need to parse it again, response.json() does it for you
empty
jinx
it said empty ๐
xd
@solemn latch Thanks
Np
you can use console.log(require("discord.js").version)
o you're still on v11
how do I update?
me: uncomfortalbe with the catapi
hypixel (minecraft server) api: like 10 pages long
okay okay so it's not giving me an error and sends the message
but
but
the image doesn't appear, would anyone have a guess to why?
@harsh moon Read https://discordjs.guide/additional-info/changes-in-v12.html
updated
what essay is pangloss typing
(message.author.presence.activities.map(msg => msg.name!=""))?message.author.presence.activities.map(msg => console.log(msg.name)) : console.log( 'Not playing.')
Hmm, it doesnt show what game I am playing. ๐ค Can someone help me?
not an essay
@pale vessel its still telling me its not a function
oh apparently obj.url is undefined, i logged it to my console and it gave me "undefined"
yeah
imma see just obj
gotta wait for it to update
flazepe it still tells me its not a function and I updated
createRole is v11 code
okay, so, this is obj
oh uh
say obj is an array
yeah

im not sure but it was working fine on glitch
