#development

1 messages · Page 583 of 1

knotty steeple
#

very much should get a vps

#

better now

uneven wren
#

I don't know how. I'll need to read up about it later

grim aspen
#

buy one

uneven wren
#

ha, not now

knotty steeple
#

also

#

SELECT * FROM tablename WHERE userId ="${msg.author.id}"
lets pretend its not a userId and instead something a user can input

#

like say a custom prefix

#

ok im not explaining this just look at the links i posted

earnest phoenix
#

While we're talking, how do I make a table like this for my blacklists?
| UserID | Reason |

knotty steeple
#

what

uneven wren
#

Ok. I do have multiple tables and one is for server customization
How I have it now is there is one select statement, and the entire code is wrapped in it. It grabs the custom prefix from the table only once

light root
#

anyone a pollmaster expert here?

tepid laurel
#

so just a quick question..

#

I have this very odd thing that I'm not getting

#

I have this error

#

but

#

I don't even really have a code neither packages installed

#

all I'm running is these few lines

#
const fs = require('fs');

fs.writeFile('mynewfile3.txt', 'Hello content!', function (err) {
    if (err) throw err;
    console.log('Saved!');
  });
#

Just tried testing out fs

#

any idea on why it errors already?

#

Even with an example from node.js site

fiery quest
#

guys, I normally use VS Code, but I'd like to try Atom, can you tell me if there's a way to get a debugger like VS Code for Atom? i'm using python

uneven wren
#

this may be a stupid question
but are you in the right directory?

tepid laurel
#

it is in one directory the main file is preset even running just the select file with node

#

does the same error

#

so yes I am

uneven wren
#

there's just been a handful of times for me where i was wondering why it was erroring only to find out i was down one dir

#

otherwise i have no clue

tepid laurel
#

yeah its not that this time

#

aight thanks anyways

#

anyone else?

#

really need to learn this whole json thing and when ya try an example already fails like woop woop

quartz kindle
#

Whats the name of your js file?

tepid laurel
#

ok.js

quartz kindle
#

Try running it with node ok.js

tepid laurel
#

okidoki

#

wew weirdest shizzle ever

#

well that worked somehow

quartz kindle
#

Well

tepid laurel
#

idk why but thanks

#

xD

quartz kindle
#

Using node . just looks for an index.js file or a startup file defined in your package.json

tepid laurel
#

ok.js was defined as that

quartz kindle
#

It cant magically know what file you want to run

tepid laurel
#

thats why im not getting it

quartz kindle
#

Eh then idk

#

Dont trust node i guess

#

xD

tepid laurel
#

XD

#

wew wait i get it already

#

right so my ok.js is in a folder in the main dir

#

cause I wanted to test if it would create the file in the folder

#

rather than in the main dir

#

so I could keep things in order

#

i see y now

#

now I just need to figure out how to preset a directory in a bot that the module will use to store the json files and so on

earnest phoenix
#

I have same problem, build module on Windows

#

And transfer it with a USB for example

#

@earnest phoenix

#

nvm i fixed it

#

Okay

tawny minnow
#

question, if i want to use webhooks on the bot list to catch votes and stuff. where do i get a url to send the hook to? would that be a url that i have created like a webhost url to catch it? or is there something built into discord to catch those?

amber fractal
#

The docs are pretty nice, I'd say. Lol.

#

It sends them to a webserver

#

That youare listening to

tawny minnow
#

when i read the docs, it didnt say anything about where to get the url for the webhook

amber fractal
#

What lang do you use

tawny minnow
#

js

amber fractal
#

You hace the js lib?

knotty steeple
#

hi who has a good cat api

#

that doesnt need sign up

amber fractal
tawny minnow
#

OH see i was on the webhook topic

amber fractal
#

The Cat API is signup, but it is free

tawny minnow
#

ill go read that area, i didnt realize that the topics above pertained to webhooks as well

knotty steeple
#

i said no sign up

#

smh

amber fractal
#

Well

#

You wont find one

#

¯_(ツ)_/¯

tawny minnow
#

ok, so i installed the lib. i got the demo code in. generated the webhook token, put that in the connection variable. when the bot connects i get a console log that says Webhook running at http://0.0.0.0:5000/dblwebhook is this correct? it seems like that should at the very least be my ip address that the bot is hosted on?

#

nvm, it does indeed work when i click "test" on the dbl site

#

thank you @amber fractal for directing me to the proper area

queen violet
#

anyone here knows how to set up docker

#

i wanna run a batch file inside a docker container whenever its started

junior summit
#
    ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
    at Client.emit (events.js:178:17)
    at WebSocketConnection.onError (C:\Users\chill\Desktop\chill\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:374:17)
    at WebSocket.onError (C:\Users\chill\Desktop\chill\discord-bot\node_modules\ws\lib\event-target.js:128:16)
    at WebSocket.emit (events.js:189:13)
    at WebSocket.finalize (C:\Users\chill\Desktop\chill\discord-bot\node_modules\ws\lib\websocket.js:185:12)
    at ClientRequest._req.on (C:\Users\chill\Desktop\chill\discord-bot\node_modules\ws\lib\websocket.js:641:12)
    at ClientRequest.emit (events.js:189:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:556:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
    at TLSSocket.socketOnData (_http_client.js:442:20)```
#

why do I keep getting that error?

empty owl
#

whats your code?

junior summit
#

Like from where my bot?

empty owl
#

yeah

#

which code caused this

junior summit
#

Like on line 180?

empty owl
#

idk

#

like the code u just put in

junior summit
#

Getting it.

#

nwm found it

#

i was coding it like just now

#

it seemed to work

#

then i died

#

it

#

lol

empty owl
#

ok

wanton walrus
#

That error is from you losing connection to discord @junior summit

#

Make sure your vps isn't closing the connection or something

junior summit
#

its an error in the code

#

not the vps

#

it crashes every time i do the command

#

but lol anyways thanks

empty owl
#

oppf

#
    let date = new Date();
  let voteUsername = bot.users.get(vote.user).username
    console.log(`User with username ${bot.users.get(vote.user).username} just voted!`);
  let voteEmbed = new Discord.RichEmbed()
    .setTitle(`${voteUsername} just voted!`)
    .addField('ID', vote.user, true)
    .addField('Time', date)
     .setColor(Math.floor(Math.random() * 16777214) + 1)
  bot.channels.get('552674443131093002').send({voteEmbed});``` doesnt work no error pls help
#

bot.users.get(vote.user).username

#

return undefined

amber fractal
#

Well is that with a test?

empty owl
#

yes

amber fractal
#

People dont have to be in a server with your bot to vote

empty owl
#

iik

amber fractal
#

It cant get a user it doesnt know

empty owl
#
dbla.webhook.on('vote', vote => {
  
  if (bot.users.get(vote.user) === undefined) {
  console.log(`User with id ${vote.user} just voted!`);

  } else {

  let voteUsername = bot.users.get(vote.user).username
    console.log(`User with username ${bot.users.get(vote.user).username} just voted!`);
  let voteEmbed = new Discord.RichEmbed()
    .setTitle(`${voteUsername} just voted!`)
    .addField('ID', vote.user, true)

     .setColor(Math.floor(Math.random() * 16777214) + 1)
  bot.channels.get('552674443131093002').send({voteEmbed});
  }```
#

this is my code

#

so if they arent in a server with my bot

#

it does ID

#

but it doesnt work

#

cause I asked my friend to do it and it doesnt show

amber fractal
#

And did it log anything

empty owl
#

it logged an ID that isnt my friends???/\

#

with this id

#

548365482864934928

amber fractal
#

You could check for tests with vote.type

empty owl
#

ok

amber fractal
#

Idk if the test id is the same every time

empty owl
#

it is

sinful lotus
#

@junior summit add a error handler on your client
client.on('error', console.error)

sinful lotus
#

ok so basically
Im setting const queue into a map as reference, so what will happen to const queue once the map was deleted?

#

will it get gced or not

#

this is more on garbage collection stuff

amber fractal
#

Um, hate to break it to you, I don't even know what gced means

sinful lotus
#

means garbage collected

#

Im just making sure that that thing gets garbage collected

amber fractal
#

so it doesnt do leaks or something

inner jewel
#

as long as it's referenced, it won't be GC'd

sinful lotus
#

but after I deleted it on the queue map, the const queue will get out of scope

#

or am I not?

#

because the only thing Im referencing to the queue is the map

inner jewel
#

if the function with it returns, yes

sinful lotus
#

wait will it not reference queue but instead, "copy" the queue ?

inner jewel
#

unless you explicitly copy, the same object will be used

sinful lotus
#

so on my case, it will just reference queue into the map?

inner jewel
#

yes

sinful lotus
#

and until the map isnt deleted, the queue will stay in memory?

inner jewel
#

any changes to it will be seen if you get the value from the map

#

yes

#

the map references it

#

(i'm keeping weak references out of this for simplicity)

amber fractal
#

Objects are a prototype, they'd point to the same location in memory iirc

#

but idk if I do

sinful lotus
#

oh ok that made my understanding on it much more better, but in arrays

#

if you reference it

#

Im pretty sure it will reference the original array since it points to the same location in memory?

inner jewel
#

are you familiar with pointers?

sinful lotus
#

in C++ I do hear them a lot

inner jewel
#

objects and arrays act like pointers (because they are)

#

so unless you copy the data to a new object/array, it'll still be the same

#

and any changes will be seen by all code referencing it

#

it's as if every object/array was just a key in a global map which has their data

sinful lotus
#

so basically

const stuff = 1
const stuff2 = stuff

stuff2 is a reference to stuff ?
so if I modify stuff then stuff2 will be the same ?
inner jewel
#

yes

sinful lotus
#

but if you modify stuff2, stuff wont change?

inner jewel
#

it will

#

when you have an object/array, you don't have it's contents

amber fractal
#

I'd like to see you modify a const mmLol

inner jewel
#

you have something which is the location of the contents

#

so you just copy the location when you assign it to something

#

when you access, both point to the same location

#

so changes to one will be seen by the other

sinful lotus
#

oh I see, so basically referencing means It will just point where is the location of the original variable?

inner jewel
#
const x = {}
x.a = 1```done @amber fractal
amber fractal
sinful lotus
#

you cant change the x object but you can change the value inside of it mmLol

inner jewel
#

you can't reassign it

#

but you can mutate the data in it

#

which is why const is a wrong name since it's not really a constant

amber fractal
sinful lotus
#

I see, so if I have reference, setting the stuff2 to null will remove the reference from stuff then?

#

and lets stuff to be gced?

inner jewel
#

no

#

a = b doesn't invalidate b

#

setting a to null won't let it be GC'd because b still exists

#

setting both to null (assuming they're the only references) will allow GC to collect it

sinful lotus
#

wait so both and not only the referenced stuff? even you nullify the original variable?

amber fractal
#

delete b mmLol

sinful lotus
#

lmao thats a big confuse there but ok I think I get a bit of gist

amber fractal
sinful lotus
#

javascript has a lot of stuff

#

but meh u just need to learn them

amber fractal
#

I knew about delete

#

not the 2nd one tho

#

What would cause this?

sinful lotus
#

it means something errored on shard 0

amber fractal
#

Well yeah

sinful lotus
#

before your bot hit ready

#

something happened

amber fractal
#

That's nice

sinful lotus
#

as for what it is

#

well idk basesd on that error

amber fractal
#

Well I didnt have an error handler at the time, never took 5 seconds to do .on('error', (error) => console.error(error))

#

Lmao

#

I just put it in

#

instead of something that could've been helpful

#

Lol

sinful lotus
#

object object

#

maybe ws error?

amber fractal
#

Well it didn't error a second time, but my bot has been taking longer to restart lately

#

not that one tho, that was for shard testing

misty lagoon
#

So im kinda dumb but is it possible to convert a GuildChannel to a Channel?

amber fractal
#

Are you familiar with classes?

misty lagoon
#

Partly

amber fractal
#

A GuildChannel is already a Channel

#

just a subclass

#

What did you need to do?

misty lagoon
#

but you cant do GuildChannel.Parent as it returns the channel's catagory

#

i need to send a message

inner jewel
#

channel.send(...)

amber fractal
#

<Channel>.send

misty lagoon
#

using channel.sendMessage()

#

so i use .send instead?

amber fractal
#

.sendMessage is deprecated

misty lagoon
#

o

#

doesnt work

#

at Client.bot.on (/app/server.js:178:14)

    at emitOne (events.js:116:13)

    at Client.emit (events.js:211:7)

    at MessageCreateHandler.handle (/rbd/pnpm-volume/9dbb066e-589a-41b7-8b37-52522343a97c/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)

    at WebSocketPacketManager.handle (/rbd/pnpm-volume/9dbb066e-589a-41b7-8b37-52522343a97c/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)

    at WebSocketConnection.onPacket (/rbd/pnpm-volume/9dbb066e-589a-41b7-8b37-52522343a97c/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)

    at WebSocketConnection.onMessage (/rbd/pnpm-volume/9dbb066e-589a-41b7-8b37-52522343a97c/node_modules/.registry.npmjs.org/discord.js/11.4.2/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)

    at WebSocket.onMessage (/rbd/pnpm-volume/9dbb066e-589a-41b7-8b37-52522343a97c/node_modules/.registry.npmjs.org/ws/4.1.0/node_modules/ws/lib/event-target.js:120:16)

    at emitOne (events.js:116:13)

    at WebSocket.emit (events.js:211:7)

(node:8804) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:8804) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
amber fractal
#

that means the channel is undefined

#

or well

#

null

#

What version of d.js are you on

misty lagoon
#
var createdchannelname = "ticket-"+ticketid;
      var ticket = message.guild.channels.find(channel => channel.name === createdchannelname);
#

11.4.2

#

is there an update

amber fractal
#

Unless you go to master

misty lagoon
#

so it should work?

gilded blaze
#

You have to account for no channel being found

amber fractal
#

well did the channel ever actually get created?

misty lagoon
#

yes

#

the creation works

amber fractal
#

Why not save the channel as you create it?

misty lagoon
#

how?

#

im using guild.createChannel()

amber fractal
#

You'd have to await the Promise

misty lagoon
#

ok

#

brb

#

so

amber fractal
#

I was assuming the channel was created in the same command

#

or am I wrong

misty lagoon
#

I use return server.createChannel(name, "text");

#

right?

#

or

#

yes the channel is created in the same command

#

it calls a function

#

that does this

amber fractal
#

You just save it like any other var

misty lagoon
#
    var server = message.guild;

    server.createChannel(name, "text");
}
#

so

amber fractal
#

Then yea

#

return it

misty lagoon
#

ok

#

should i use async

amber fractal
#

I think you have to

misty lagoon
#

ok

amber fractal
#

unless .then

#

I find async easier

misty lagoon
#

ok

#

the test

#

ok

#

so it works

#

but .send doesnt work

#

so ima try .sendMessage idk

#

nope

#

I think it doesnt return the value.

#

this should work, right?

#
var ticket = makeChannel("ticket-" + ticketid, message);
amber fractal
#

You need to await it

misty lagoon
#

the function?

amber fractal
#

it's return value is a promise

misty lagoon
#

or like

#

await var

amber fractal
#

var name = await func()

#

I think mmLol

misty lagoon
#

yeash

#

lol

#

FINALLY

#

yay

#

thank you

amber fractal
#

Mhm

west skiff
#

so I'm trying to make a music bot

#

I know

#

ew

#

ok I have a question but I'm going to wait a sec

#

ok so what do y'all use to stream audio from youtube?

sinful lotus
#

easiest method is
ytdl + discord.js voice

west skiff
#

you're talking about downloading the whole video before playing it?

#

I know I can fall back to that but I'm trying to stream it also I think I just found out a way

sinful lotus
#

no

#

ytdl-core can stream the video while it is downloading

amber fractal
#

^ easiest way

west skiff
#

ooh

#

Well I think I'm going to keep using pafy to get the direct url then stream it from that

bright spear
earnest phoenix
#

So well,
I've tried almost everything, but I can't seem to be able to change the bots presence for some reason.
I'm clearly doing something wrong, but what FrogThink

await client.change_presence(game=discord.Game(name="Test", type=1))
#

Currently just trying that, didn't work as well so :/

slender thistle
#

Rewrite branch?

earnest phoenix
#

Hell no, I can't be arsed to start with rewrtie right now. Async

slender thistle
#

type is wrong

#

I doubt it exists in async

earnest phoenix
#

hm shit

west skiff
#

yeah I've got it all working except I just need to figure out how to transcode the webm audio (vorbis or something like that I think) to raw pcm

#

as its streaming

sinful lotus
#

I believe you can use ffmpeg for that

#

you just need to sset the ffmpeg arguments

west skiff
#

yeah I was thinking of it I just don't know much about ffmepg or how I would get it to work with a stream

sinful lotus
#
[
  '-analyzeduration', '0',
  '-loglevel', '0',
  '-f', 's16le',
  '-ar', '48000',
  '-ac', '2',
]
#

that converts the audio into "S16LE" 16-bit signed PCM audio.

west skiff
#

ok sorry but I'm dumb so would that work to like do it by chunks

sinful lotus
#

you said you get the stream right?

west skiff
#

yeah I got that and I'm able to read the stream

sinful lotus
#

ok is it a readable stream?

west skiff
#

uh

#

I think so

sinful lotus
#

since I deal with node.js so Im not sure what is the counter part on Python

#

I think you use python?

west skiff
#

It's through an http request and just reading 20 bytes at a time right now because 20 bytes is what discordpy asks for

#

but I can change that number

sinful lotus
#

do you use ffmpeg right now?

west skiff
#

Nope first thing I tried was just directly plugging that in but it needs to be converted so thats what I need ffmepg for

sinful lotus
#

ok so to give you an idea, the arguments would be the ffmpeg arguments which you will use for the ffmpeg conversion

#

that arguments I gave convert the audio to pcm audio

#

since Im not really a python programmer thats all the help I can give you, but I would advice to use an ffmpeg package in your programming language

#

to make your life easier

west skiff
#

I get that I was just wondering if it say I only gave ffmepg n bytes if it would still work but I can just play around

#

thanks!

sinful lotus
#

also I think it may work since readable streams in node.js work like that

#

although you feed it directly the "data"

fiery nebula
sinful lotus
#
author: {
      name: client.user.username,
      icon_url: client.user.avatarURL
    }
fiery nebula
earnest phoenix
sinful lotus
earnest phoenix
#

what should i do?

unique nimbus
#

You are on python2

earnest phoenix
#

oh

unique nimbus
#

You need to upgrade to pythone

#

Python3

earnest phoenix
#

how does one do that?

unique nimbus
#

What is are you on?

#

Os

earnest phoenix
#

mac

unique nimbus
#

If you are on rewrite download 3.6.7

#

If not 3.6.5

#

Yes

fiery nebula
#

ew mac

unique nimbus
#

Everyone has their preferences

earnest phoenix
#

yeah ik mac is terrible

unique nimbus
#

Download Linux onto your mac

earnest phoenix
#

wait

#

i do have it

unique nimbus
#

Oh

#

When you are updating do python3 pip install

#

If I remember correctly

earnest phoenix
#

/Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file 'pip': [Errno 2] No such file or directory

unique nimbus
#

O

earnest phoenix
#

oh cheers

#

it works :)))

#

thankkks mate

unique nimbus
#

No Problemo

#

@earnest phoenix

slender thistle
#

Ahh, people suggesting rewrite lunaGasm

unique nimbus
#

Yes ily2

strange compass
#

what to do with a customized

#

widget

#

😐

unique nimbus
#

Wdym

strange compass
#

the thing in website

#

mods ?

#

😐

#

are you there

amber fractal
#

Well what do you mean

earnest phoenix
#

Would not you have a way to create a subfolder in a folder in nodejs?

languid dragon
#

what

kind wyvern
#

help me with this

coral trellis
#

It can't be caps

#

Or it can't have spaces I mean

kind wyvern
#

all small

rocky dagger
marble needle
#

why don't you post the error you are getting and/or stop copying code you can't troubleshoot

rocky dagger
#

there is no errors bot when i write -pay @ user <cash> and i have the amount myself i won't give it becouse of this line:js if(coins[message.author.id] > args[1]) { return message.reply(`You only have ${coins[message.author.id].coins} coins and you need ${args[1]} coins!`) }

#

and when i delete that line the user gets the cash but I don't lose it

marble needle
#

you check if the user has more coins than specified in the command arguments yet you tell them they don't have enough even if they do

amber fractal
#

Folders can have spaces Thonk

earnest phoenix
#

How to see which servers is my bot
code is

const botconfig = require("../botconfig.json");
let color = botconfig.color

module.exports.run = async (bot, message, args) => {
    let bicon = bot.user.displayAvatarURL;
    let string = '';
    bot.guilds.forEach(guild => {
    string += guild.name + '\n';})
    let bt = bot.user.username;
    let botembed = new Discord.RichEmbed()
        .setColor(color)
        .addField("Servers In", string)
        .setTimestamp()
        .setFooter("Command Ran By: " + message.author.username, message.author.avatarURL);
    message.channel.send(botembed);
}

module.exports.help = {
    name: "servers"
}```
But its not possible becasue console error 
```(node:400) UnhandledPromiseRejectionWarning: RangeError: RichEmbed field values may not exceed 1024 characters.```
How can i fix that
Or how can i create when i typing servers list on servers , when i typing servers 1 another servers and other
marble needle
#

use code blocks

#

the error clearly tells you what's wrong, your string contains every guild's name your bot is in and you try to press that into an embed. Said string is larger than 1024 characters and thus errors out when you're trying to send the embed

earnest phoenix
#

I know that but how can fix this

marble needle
#

simply use the amount of servers as an integer rather than all of their names heavythonk

uneven wren
#

or write it to a text file

marble needle
#

and that "solution" is going to help him achieve his goal in what way exactly?

earnest phoenix
#

how can i write it to a text file

marble needle
#

throwing out servers your bot is in isn't the best idea either way so i suggest you stick to raw numbers rather than server info

uneven wren
#

i dont remember how. I used to do it when working with .json but i yeeted that altogether

#

use stack overflow, im sure its a fairly simple process

earnest phoenix
#

how can i use that

#

can u show me

#

😕

marble needle
#

stackoverflow is a website

#

google it, use it. it's not that hard

dusky marsh
#

Obviously Google is too hard for most, you're simply expecting too much

#

Smh

earnest phoenix
#

listen i want create thath
http://prntscr.com/mu2pi3
when i typing example invites 2
Bot show me invite 2 page, when i typing invites 3 bot show me invite 3 page

Lightshot

Captured with Lightshot

uneven wren
#

I see what you're trying to do but its beyond my abilities - I've forgotten how to work with json because sql handles data better. You're gonna probably have to run a loop to limit 10 per page, again stackoverflow will really help

amber fractal
#

You actually arent allowed to have a public servers command

uneven wren
#

I didnt know thats not allowed, but yeah I'm not even sure why you need to list the server names anyway. seems the standard for global leaderboards leaves out the server names anyways

earnest phoenix
#

I've been quoting it as an example because I did not know how to explain otherwise what I want , because I do not know how to speak good English and use google translate

chrome olive
#
    let user = message.mentions.users.first() || message.author;

    const canvas = Canvas.createCanvas(127,127)
    const ctx = canvas.getContext('2d');

    const { body: a } = await snekfetch.get(user.avatarURL);
    const avatar = await Canvas.loadImage(a);
    ctx.drawImage(avatar, 10,10,230,230)
    
    const attach = new Discord.Attachment(canvas.toBuffer(), 'avatar.png');
    message.channel.send(attach);```
#

how i can curve the avatar

#

i don't want to create a circle

quartz kindle
#

Like rounded borders?

tepid laurel
#

Quick question lads

amber fractal
#

Quick answer mate

tepid laurel
#

If I were to pass a param to a function that is a class

#

It passes it like an object right?

amber fractal
#

It'd pass the instance of the class

tepid laurel
#

That I could use right away as an object rather than having to put all values in a new object

#

Yea an instance I'd be passing

#

Just wondering if that would be an object useable for e.g putting it in a json file

amber fractal
#

It'd have it's methods and properties

#

It doesn't pass like an object

tepid laurel
#

Alright so, I'd have to manually put it in an object?

amber fractal
#

Yes, you could make a method in the class for this

tepid laurel
#

Aye I see

#

Thank you mate

#

used a getter

#

that should be fine if I believe

#
get classData() {
        return {
            name: this.name,
            id: this.id,
            globalLevel: this.globalLevel,
            specialAccess: this.specialAccess,
            members: this.members
        }
    }
shell blade
#

Anyone know why custom emojis won't work with my bot?

tepid laurel
#

depends how you use it

shell blade
#

It doesn't work with both reacting and in messages.

tepid laurel
#

again

#

how do you try to use it

shell blade
#

I use the text given with \:emoji:.

tepid laurel
#

ohh I see tarp

#

Well I used a getter now

#

On the class

#

Should work the same right?

amber fractal
#

I don't use getters, so I don't actually know how they work lmao

tepid laurel
#

Oh well getters dont take params

amber fractal
#

I read about them

tepid laurel
#

They just return whatever you let it return

#

bad at explaining

amber fractal
#

Basically you dont need the ()'s?

tepid laurel
#

It is a function but it does not function as one

#

rip

#

golden explanation of the day

amber fractal
#

Yeah, yours will work

#

I just changed it into a getter

tepid laurel
#

You work a lot with classes?

amber fractal
tepid laurel
#

@shell blade Google discord.js using emojis

#

emojis have an id

#

use that to send

amber fractal
#

Oops not getName

tepid laurel
#

how come you have function run()

amber fractal
tepid laurel
#

classes dont need that

amber fractal
#

It's not

#

I have the class

#

then 2 functions

#

to test the passing

tepid laurel
#

hm I see

amber fractal
#
class Person{
  constructor(name, age, likes){
    if(typeof name != "object" || name.length != 2){
      throw new Error("Name must be an array with 2 entries (First name and last name).")
    }
    if(age < 0){
      throw new Error("Age must be greater than 0")
    }
    if(typeof name != "object"){
      throw new Error("Likes must be an array.")
    }
    this.firstName = name[0]
    this.lastName = name[1]
    this.age = age
    this.likes = likes
  }

  setName(name){
    if(typeof name != "object" || name.length != 2){
      throw new Error("Name must be an array with 2 entries (First name and last name).")
    }
    this.firstName = name[0]
    this.lastName - name[1]
  }

  getName(){
    return `${this.lastName}, ${this.firstName}`
  }
  
  get toObject(){
    return {
      firstName: this.firstName,
      lastName: this.lastName,
      age: this.age,
      likes: this.likes
    }
  }
}

function run(){
  let person1 = new Person(["First", "Last"], 15, [])
  test(person1)
}
function test(person){
  console.log(person.toObject)
}
run()```
#

I just took it as an example

tepid laurel
#

yeahh I was already thinking

#

lmaoo

#

I'd be dying if you'd do something like..

#
class random {
    constructor() {
    }
function ok() {
    }
}
amber fractal
tepid laurel
#

😂

amber fractal
#

but yours should work

#

the only difference with the get is that I didnt need the parentheses

tepid laurel
#

aye aye

#

however

#

if Im not wrong

#

you cant do things like

#

e.g

#
get random()  {
    this.that = ok
}
#

Nearly sure that get only returns data

amber fractal
#

You can

tepid laurel
#

hmm odd

#

There was something about get

#

I cant really recall for sure

amber fractal
#

You just can't pass params

#

If you added parentheses it would say ... is not a function

tepid laurel
#

Yeah thats true

#

Ok so I used the get now in a function

#
createJSONFile(customPerm) {
        if(!customPerm instanceof CustomPerm) throw new Error('Passed value requires an Custom Permission instance.');
        const data = customPerm.data();
            fs.writeFile(`${this.dataPath}/${data.name}.json`, data, (err) => {
                if(err) throw new Error(err);
            });
        return true;
    }
amber fractal
#

I need to go, I'm in civics right now, just had some down time.

tepid laurel
#

Ohh aight mate

amber fractal
#

:Wave: good luck

#

👋

tepid laurel
#

You too 😄

shell blade
#

Alright, thanks. Sorry for the late reply.

tepid laurel
#

Np

junior summit
#

what is wrong with this I got an error

amber fractal
#

With what

junior summit
#

if (message.guild.me.voiceChannel) return message.channel.send('Sorry, the bot is already connected to the guild.');

amber fractal
#

And the error?

junior summit
#

i says that message.guild.me.voiceChannel has error

#

me.voicechannel

#

i ant sure if me is the issue

mossy vine
#

weird, it should exist

#

unless message isnt defined

junior summit
#

should i change it

#

like is there a better way

amber fractal
#

What does the console say exactly

#

Copy paste or picture

junior summit
#

i closed the error

#

so i dont know

mossy vine
#

then run it again

junior summit
#

oof

#

bit i am not sure what caused it

#

cuz it ran fine

#

then some eorrr

#

hit

mossy vine
#

then run it again and send us the error

amber fractal
#

We cant help without the error,it should work

mossy vine
#

we cant help if we dont even know what the error is

junior summit
#

if it comes back then i will ask again

#

idk why

amber fractal
#

The only way i see it not working is if the guild doesn't exist

#

I.e it was a dm

junior summit
#

wait

#

so if i dm the bot

#

how do i shut down dms

#

like make it not care

amber fractal
#

Check the channel type

junior summit
#

ok

#

my bot is so dumb it works for a day then your like its not having errors then 1 sec later it crashes lol

#

oh i got this

#

(node:3492) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'voiceChannel' of null
at Client.<anonymous> (C:\Users\chill\Desktop\chill\discord-bot\bot.js:445:25)
at Client.emit (events.js:194:15)
at MessageCreateHandler.handle (C:\Users\chill\Desktop\chill\discord-bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\chill\Desktop\chill\discord-bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\Users\chill\Desktop\chill\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\chill\Desktop\chill\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\chill\Desktop\chill\discord-bot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:189:13)
at Receiver._receiver.onmessage (C:\Users\chill\Desktop\chill\discord-bot\node_modules\ws\lib\websocket.js:137:47)
at Receiver.dataMessage (C:\Users\chill\Desktop\chill\discord-bot\node_modules\ws\lib\receiver.js:409:14)
(node:3492) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3492) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

#

when i dmed

#

but it never crashed

#

so idk how it crashed

amber fractal
#

Yeah, because the guild doesnt exist

mossy vine
#

because message.guild is not defined there

amber fractal
#

return on dm

junior summit
#

show how to fix

amber fractal
#

No spoonfeed

junior summit
#

oof

#

uh

#

ok

#

imma figure this out

#

why

#

does it not crash

#

wtf

amber fractal
#

Well it will in future versions

#

As non handled promise rejections are deprecated

unreal rampart
#

@bot.command(pass_context=True)
@commands.has_permissions(kick_members=True)
async def kick(message, userId: discord.User):
await bot.kick(userId)

#

how can i modify this to not work when someone tries to kick me

ruby dust
#

first off, it's already a mistake by using async version

#

it's a very outdated library from around a year ago, at least

unreal rampart
#

😦

ruby dust
#

secondly, learn python before writing code

unreal rampart
#

D:

#

how would i use the new library?

ruby dust
#

install the rewrite version

unreal rampart
#

i dont know javascript btw

#

how do i do that`?

ruby dust
#

javascript?

#

your code looks like python

marble needle
#

prolly cause it is

ruby dust
#

duh

unreal rampart
#

correct?

ruby dust
#

yes

unreal rampart
#

how would i then use this library

ruby dust
#

but not only asking for help with code, also not knowing what language you are using? go back to school is all the answer I can give you

marble needle
#

how have you been using the old library

ruby dust
unreal rampart
#

i know that i am using python, i am not a complete dumbnut, i just wanted to tell you that i dont know .js before you told me to use discord.js instead

ruby dust
#

I was not telling you anything language related?

marble needle
#

he told you your lib was outdated. that being the case i doubt anyone will throw a lib written in a different language at you if there's an up-to-date one for your language of choice

ruby dust
#

I was telling you to learn python because you clearly do not know anything about it and trying to make something as big as a discord bot, it's just a terrible practice

#

development in general is a complicated thing, no one will help you if even you don't know what you're doing

uneven wren
#

eh tbf getting nodes and shite set up is confusing in itself

unreal rampart
#

well thanks, but all i was asking is, could i simply use an if statement to check if userId equals my user id, and then to not do anything based on that

ruby dust
#

basically yes

uneven wren
#

i had to get someone to walk me through to actually get my bot to login, from there it was a breeze

unreal rampart
#

cause from what i've seen, if statements are just ignored

ruby dust
#

again, it's best if you learn the basics of python, at the very least

unreal rampart
#

..., it just jumps over the if statement, as in if i did
if userId == "Dr. Runk#0283":
return False

ruby dust
#

...that's not even the id

uneven wren
#

use the id number

marble needle
#

oh boy

unreal rampart
#

if i do print(userId) that is what show up

#

and yes, i have tried the ID number aswell

ruby dust
#

259695208453636106

#

that's your id

unreal rampart
#

don't you think i tried that aswell?

amber fractal
#

No

ruby dust
#

considering your knowledge, no

grim aspen
#

wait

#

what library is he actually using right now?

uneven wren
#

i dont know python (im js boi)
but get rid of the "'s maybe and use the id

ruby dust
#

async

#

idk about async, but on discord.py rewrite ids are ints

marble needle
#

i highly doubt the python lib returns your id as an integer rather than a string

amber fractal
#

Its not a lib thing, ids are just snowflakes.

#

If a lib returns your tag

#

Then theres something wrong with the lib

ruby dust
#

it's kind of a lib thing, discord.js returns them as strings, discord.py rewrite returns as integers

amber fractal
#

It cant

ruby dust
#

wdym

unreal rampart
#

@bot.command(pass_context=True)
@commands.has_permissions(kick_members=True)
async def kick(message, userId: discord.User):
if userId == "259695208453636106":
return False
else:
await bot.kick(userId)

#

this doesnt work

marble needle
#

define "it can't", you surely could if you wanted to

#

there's nothing preventing you from converting its type before returning

ruby dust
#

@amber fractal are you js?

amber fractal
#

It might auto convert

#

But its always a string

ruby dust
#

are you js?

uneven wren
#

if it converts it to int then he shouldn't be using quotes

unreal rampart
#

@uneven wren good idea

#

might try that

marble needle
#

read the docs and learn python instead of trying random things hmm

amber fractal
#

Yes, but the http request will always gove you a string, the lib might be doing the conversion

ruby dust
#

then don't fucking assume, I'm literally using discord.py rewrite and it's an integer, it's a fucking lib thing

amber fractal
#

Because Snowflake IDs are up to 64 bits in size (e.g. a uint64), they are always returned as strings in the HTTP API

#

It's not an assumption

#

It's in the docs

#

Your lib does the conversion

unreal rampart
#

just kicked myself

#

that doesnt work

marble needle
#

if you as a library dev are having a wonderful day and decide to parse through the string and convert it to an integer there is literally nothing preventing you from doing that no matter what the api returns

ruby dust
#

no one even asked about what ids even are, this was a discussion how the lib handles it

#

steven you're only making this more complicated for no reason

amber fractal
#

And you're being a dick Thonk

uneven wren
#

if userId is 259695208453636106:

#

I'll shut up now
I barely know any python

ruby dust
#

well I'm sorry, it's not me that said that ids are strings out of the blue to the complete python noob when discord.py clearly uses them as ints

unreal rampart
#

i kicked myself again

uneven wren
#

Sorry I can't help more, I don't use python for coding :/

unreal rampart
#

ok no worries

ruby dust
#

anyway, your issue is that you defined your userId as a discord user object, so use userId.id to refer to the user object's id

unreal rampart
ruby dust
#

yeah, but the async version may or may not use ids as strings

unreal rampart
#

i could actually use userName, instead, but that doesnt work with spaces in the names

ruby dust
#

you can fix that

#

but a * as a first character on that variable

uneven wren
#

i would stick with id because id's are static

ruby dust
#

it's even better to just use user cause it's still a user object

#

userName is misleading cause you think it's already a user name

#

userName.name looks dumb

unreal rampart
#

if user.id == "asdad": ot if user.user

left briar
#

Where can I invite Mee6?

uneven wren
#

lol

left briar
#

Thanks

ruby dust
#

does getting an invite object have any strict ratelimits?

frozen bough
#

How can i use node.js? All i get is a prompt, and not a windows form application :L

earnest phoenix
#

well

#

yes

#

frameworks are mostly packed with CLIs, not your fashionable windows apps

#

learn to work with CLIs because that's a big part of programming in general

frozen bough
#

uhm, ok.

earnest phoenix
#

i could just do client.commands[arg] inside the if statement that function is called in instead saving the spaghetti

plain anvil
#

Anyone have acquaintance with Reaction Role's creator? I have some questions about its v2 API, looking to integrate my system with it.

jagged birch
#

Go to the support server

amber fractal
#

Well Fishy left

#

idk why tho

ruby dust
#

you sure

#

hmm

amber fractal
#

Yes

#

Positive

#

Also, I save an instance of a class into a db, but I can't use the getter/setter methods anymore, is this normal or did I bork something

#

Well acturally nothing works

#

Ping me if you have a response pls.

amber fractal
#

Wait now it's just saving the name and the password it doesn't even have user Thonk

earnest phoenix
#

how do you make a bot say something in a loop

quartz kindle
#

Why would you want an infinite loop?

earnest phoenix
#

for my nsfw channel

#

i use too have a bot like the but someone banned it

#

@quartz kindle do u know how too

#

or how to make it say something a amount of times

quartz kindle
#

Are you trying to code a bot, or make an existing bot do that?

earnest phoenix
#

make a existing bot do it

quartz kindle
#

You cant make a bot do anything other than what it was coded to do

#

So you have to find a bot that does that

earnest phoenix
#

O

#

I made a bot

#

I want to know what to put in the code to make it do that

#

I thought u ment did I make a bot

#

@quartz kindle

quartz kindle
#

Well, if you are coding your own bot, which language and library are you using?

earnest phoenix
#

python

quartz kindle
#

An infinite loop is usually always bad, so you better stick with sending messages, if you really need that. But be aware that it is considered api abuse, and might get you rate limited if not worse

#

To send multiple messages, you can use a for loop

earnest phoenix
#

can u send me what the line looks like

quartz kindle
#

I dont know which library youre using, and i dont use python, but it should be something like this, just for you to get an idea py for x in range(10): // 10 messages ctx.send(message)

empty owl
#

hey

#

bot.users.get(vote.user).username returns undefined'

#

in this context

 if (bot.users.get(vote.user) === undefined) {
  console.log(`User with id ${vote.user} just voted!`);

  } else {
  
  let voteUsername = bot.users.get(vote.user).username
    console.log(`User with username ${bot.users.get(vote.user).username} just voted!`);
  let voteEmbed = new Discord.RichEmbed()
    .setTitle(`${voteUsername} just voted!`)
    .addField('ID', vote.user, true)

     .setColor(Math.floor(Math.random() * 16777214) + 1)
  bot.channels.get('552674443131093002').send({voteEmbed});
  }```
#

like always

#

when the person is in a guild with the bot

amber fractal
#

Why not just put it in a try/catch?

empty owl
#

where

#

ill try

#

but how would that help

amber fractal
#

Well

#

That's just how mine works tb

#

tbh*

empty owl
#

oh

#

so like

amber fractal
#

just try and get the user, if it doesnt exist do the default

empty owl
#
try {
bot.usersavdonkmdc
}
catch {




}```
#

what do I catch

#

()

#

catch(error)\

hushed berry
#

anything

amber fractal
#

Well the catch is just there for errors

empty owl
#

like that

amber fractal
#

you test for the user

#

if(!user)

empty owl
#

if it exists?

amber fractal
#

I honestly dont know why yours doesnt work

empty owl
#

oh

amber fractal
#

I would recommend saving bot.users.get(vote.user) in a variable then checking if(!varName) return //stuff

empty owl
#

look

#

[K] FFFFFFFFFFFFFFFFFFFFFToday at 8:02 PM
x-eval bot.users.get(345349646253817857 )
UsagiXBOTToday at 8:02 PM
undefined

amber fractal
#

Well

#

it needs to be a string

empty owl
#

ok

#

x-eval bot.users.get('345349646253817857').username

#

works

#

but

#

vote.user doesnt?

amber fractal
#
if(!user){
//stuff
}```
empty owl
#

ok

#

@amber fractal bot.users.get(vote.user) returns undefined

amber fractal
#

Did you hit test for this

empty owl
#

yea

#

the test id is my id tho

#

those find work

amber fractal
#

Well it works for me Thonk

empty owl
#

can I see your code

amber fractal
#

Well it's the same as the example I gave you earlier

empty owl
#

oh ok

#

does bot.users.get(vote.user) return a string

amber fractal
#

it returns the id of the user

sinful lotus
#

you can also just rely on dbl api on whole webhook thing tho

empty owl
#

in a string?

#

what

sinful lotus
#

without needing to touch your client.users

empty owl
#

oh yeah

#

vote.username

#

right

sinful lotus
#

nope

#

that isnt a thing

amber fractal
#

He's testing if the user shares a guild so he can post their username

grim aspen
#

so i was wondering

empty owl
#

argh!

grim aspen
amber fractal
#

Set it's activity

grim aspen
#

where it says it's watching something

empty owl
#

dude

sinful lotus
#
    async _fetch_user(id) {
        const req = await fetch(`https://discordbots.org/api/users/${id}`, {
            headers: { authorization: this.dbl_token }
        })
        const user = await req.json()
        return user.username + '#' + user.discriminator
    }

    async _send_new_vote_embed(user_id) {
        if (!this.webhook) return 
        const tag = await this._fetch_user(user_id)
        await this.webhook.send({
            embeds: [{
                color: 0x095562,
                description: `📥 New User: **@${tag}** (${user_id}) voted`,
                timestamp: new Date(),
                footer: {
                    text: `💾 ${this.storage.size} stored votes`
                }
            }]
        })
    }

    _onVote(req, res) {
        if (req.headers.authorization !== this.auth) {
            res.status(401).send('Unauthorized')
            console.log('[Notice] Rejected Post Request, Details Below')
            console.log(req.headers)
        } else {
            // Handle votes here
            this._send_new_vote_embed(req.body.user).catch(console.error)
        }
    }

this is how my separate handler does it, if you would prefer to see how the whole code does it just ask me @empty owl

amber fractal
#

d.js?

grim aspen
#

yup

empty owl
#

okj thanks

amber fractal
#

What in the hell is that tho mmLol

sinful lotus
#

thats how my own webhook work for dbl

#

as I said I dont need to rely on client.users which may return uncached users

empty owl
grim aspen
#

oh

#

thanks

empty owl
#

np

amber fractal
#

Why would it

#

It's deprecated

empty owl
#

ik

amber fractal
empty owl
#

the answers

#

HEY I WAS GOING THERE

amber fractal
#

So use setActivity

grim aspen
#

k thanks

amber fractal
#

🤷

empty owl
#

bot.users.get(vote.user)

#

return undefined

#

🤷

sinful lotus
#

I gave you a snippet did you not understand it?

empty owl
#

nope

sinful lotus
#

this is the class contains that code, so I just invoke this which is the "class" of that methods, then invoke the methods

amber fractal
#

I didnt understand it either mmLol

sinful lotus
#

da f

empty owl
#

oh

#

but how to do it with dbl webhooks

sinful lotus
#

if t he user is cached it will work

#

or you have your own playerstorage stuff

#

thats why it works

amber fractal
#

it's my db

empty owl
#

y u delete i didnt see it yet

sinful lotus
amber fractal
#

It was an accident

empty owl
#

ok

sinful lotus
#

look on src haruna.js

#

the vote will be received on _onVote

#

just gonna ask you, do you understand classes?

empty owl
#

yeah but how do I fix my bot.users.get in dbl webhooks

#

no

sinful lotus
#

then thats the reason why you cant understand my code

empty owl
#

oh

sinful lotus
#

ok I'll explain it in a more beginner friendly one

#

basically

#

in _onVote call

amber fractal
#

Ah I see

#

you're going to the discordbots api

sinful lotus
#

this._send_new_vote_embed(req.body.user).catch(console.error)

amber fractal
#

when they vote

sinful lotus
#

I call this

empty owl
#

oh

sinful lotus
#

async _send_new_vote_embed(user_id) and when I call that, I invoke this function

#

const tag = await this._fetch_user(user_id)
and there is this call to a function in my handler which is the
async _fetch_user(id)

empty owl
#

wait

amber fractal
#

Wait so you dont even need the dblapi for that do you

empty owl
#

I think I know how to fix it

#

do I have to login again?

amber fractal
#

it's basically your own little vote lib for dbl

sinful lotus
#

no you can just rely entirely on dbl api

empty owl
#

bot.login

sinful lotus
#

no

empty owl
#

oh

sinful lotus
#

that is my own little vote lib for dbl api

#

as tarpegon said lmao

#

that doesnt rely on your bot

#

so even the user is not cached on your bot

#

it would be fine

#

client.users on discord bot doesnt contain all the users in discord

empty owl
#

why would i need a username if they dont use my bot

sinful lotus
#

but they voted

#

also not everyone is cached in start

empty owl
#

I just figured it out

#

I have to login again

sinful lotus
#

and that could cause spotty stuff in your bot

empty owl
#
dbl.webhook.on('vote', vote => {
  let vUser = bot.users.get(vote.user)
  
  if (!vUser) {
  console.log(`User with id ${vote.user} just voted!`);

  } else {
  
  let voteUsername = bot.users.get(vote.user).username
    console.log(`User with username ${bot.users.get(vote.user).username} just voted!`);
  let voteEmbed = new Discord.RichEmbed()
    .setTitle(`${voteUsername} just voted!`)
    .addField('ID', vote.user, true)

     .setColor(Math.floor(Math.random() * 16777214) + 1)
  bot.channels.get('552674443131093002').send({voteEmbed});
  }
});

bot.login(process.env.TOKEN)```
#

see

amber fractal
#

You can set it to cache all users on start mmLol

#

Bad idea

#

dont do it

empty owl
#

why

sinful lotus
#

wait what

#

double bot.login?

empty owl
#

yea

sinful lotus
#

ahhh

#

here I am trying to help you

empty owl
#

gonna crash right

amber fractal
sinful lotus
#

and what you did is just trololol

amber fractal
#

Yeah, dont do it

sinful lotus
#

I even gave you the snippet

empty owl
#

0ok

sinful lotus
#

for supreme spoonfeed, if you have node-fetch in your bot

empty owl
#

the reason why it doesnt work is because

#

dbl is in server.js

#

and my fs is in index.js

sinful lotus
#

wait wat

empty owl
#

.-.

amber fractal
sinful lotus
#

that doesnt make any sense to me now

amber fractal
#

what does fs have to do with fetching a user?

empty owl
#

like my main bot code is in index.js

#

and my dbl code is in server.js

#

but I cant login again because it bad

sinful lotus
#

thats how my little library works

#

but it gets the user fine without any bot code

#

the way is to just grab it also from dbl

empty owl
#

i use express

sinful lotus
#

fastify is same as express but better

empty owl
#

oh

amber fractal
#

I just use http mmLol

sinful lotus
#

fastify's overhead compared to express is less

empty owl
#

so do I have to export something into server.js

#

to make it work

sinful lotus
#

you have node-fetch?

amber fractal
#

You can require server.js in index.js

empty owl
#

i do

#

both

sinful lotus
#

if you have node fetch require it on your server.js

empty owl
#

opk

sinful lotus
#
    async function _fetch_user(id) {
        const req = await fetch(`https://discordbots.org/api/users/${id}`, {
            headers: { authorization: this.dbl_token }
        })
        const user = await req.json()
        return user.username + '#' + user.discriminator
    }

copy that and replace authorization to your dbl token
invoke it with

const tag = await _fetch_user(vote.user)
#

thats how easy the snippet I gave you

amber fractal
#

Wait that little library thing you gave, all you'd have to do is make a new Haruna with the port, auth, length, token and optional dir and you're fine right?

empty owl
#

do I just

sinful lotus
#

yes

amber fractal
#

Seems easy asf

#

Just a question, what is length tho

sinful lotus
#

in my readme it says

This api / webhook vote handler is oversimplified. As long as you can start it, it will handle everything for you to save you the hassle of creating your own vote handler.
empty owl
#

where do I put this

#

const tag = await _fetch_user(vote.user)

sinful lotus
#

length is the cache lifetime of your user in cache @amber fractal

#

@empty owl on vote event of you dbl handler

empty owl
#

ok

sinful lotus
#

then console.log(tag)

#

u will see the magic

empty owl
#

ok

#

thios goes?

#

async function _fetch_user(id) {
const req = await fetch(https://discordbots.org/api/users/${id}, {
headers: { authorization: process.env.DBLAUTH }
})
const user = await req.json()
return user.username + '#' + user.discriminator
}

sinful lotus
#

below the on vote event

empty owl
#

ok

sinful lotus
#

not inside the vote event

empty owl
#

ok

sinful lotus
#

try to test it

amber fractal
#

Oh wait that's acturally pretty sext

#

sexy*

empty owl
#

undefined#undefined

User with id 345349646253817857 just voted!

amber fractal
#

ngl

sinful lotus
#

ok so could you show your code rn?

empty owl
#
dbl.webhook.on('vote', async vote => {
  const tag = await _fetch_user(vote.user)
  let vUser = bot.users.get(vote.user)
  console.log(tag)
  if (!vUser) {
  console.log(`User with id ${vote.user} just voted!`);

  } else {
  
  let voteUsername = bot.users.get(vote.user).username
    console.log(`User with username ${bot.users.get(vote.user).username} just voted!`);
  let voteEmbed = new Discord.RichEmbed()
    .setTitle(`${voteUsername} just voted!`)
    .addField('ID', vote.user, true)

     .setColor(Math.floor(Math.random() * 16777214) + 1)
  bot.channels.get('552674443131093002').send({voteEmbed});
  }
});
    async function _fetch_user(id) {
        const req = await fetch(`https://discordbots.org/api/users/${id}`, {
            headers: { authorization: process.env.DBLAUTH }
        })
        const user = await req.json()
        return user.username + '#' + user.discriminator
    }```
sinful lotus
#

the whole if possible

empty owl
#

ok

#

const express = require("express");
const app = express();
const fetch = require('node-fetch');
var HttpProxy = require('http-proxy')
app.get("/", (request, response) => {
  console.log("Ping received!");
  response.sendStatus(200);
});
const Discord = require("discord.js");
const bot = new Discord.Client();
// listen for requests :)
const listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

const DBL = require('dblapi.js');

const http = require('http');


const server = http.createServer(app);







const dbl = new DBL(process.env.DBLTOKEN, {  webhookAuth: 'hehnothanks', webhookServer: listener });
dbl.webhook.on('ready', hook => {
  console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
  console.log('Ready! Webhook running at /dblwebhook')
});
dbl.webhook.on('vote', async vote => {
  const tag = await _fetch_user(vote.user)
  let vUser = bot.users.get(vote.user)
  console.log(tag)
  if (!vUser) {
  console.log(`User with id ${vote.user} just voted!`);

  } else {
  
  let voteUsername = bot.users.get(vote.user).username
    console.log(`User with username ${bot.users.get(vote.user).username} just voted!`);
  let voteEmbed = new Discord.RichEmbed()
    .setTitle(`${voteUsername} just voted!`)
    .addField('ID', vote.user, true)

     .setColor(Math.floor(Math.random() * 16777214) + 1)
  bot.channels.get('552674443131093002').send({voteEmbed});
  }
});
    async function _fetch_user(id) {
        const req = await fetch(`https://discordbots.org/api/users/${id}`, {
            headers: { authorization: process.env.DBLAUTH }
        })
        const user = await req.json()
        return user.username + '#' + user.discriminator
    }


amber fractal
#

I believe with their code you dont need to check for the user anymore

sinful lotus
#

ok so could you delete first the other code on vote?

empty owl
#

?

amber fractal
#

Because you get the username and discrim anyways

empty owl
#

thi9s

#

} else {

let voteUsername = bot.users.get(vote.user).username
console.log(User with username ${bot.users.get(vote.user).username} just voted!);
let voteEmbed = new Discord.RichEmbed()
.setTitle(${voteUsername} just voted!)
.addField('ID', vote.user, true)

 .setColor(Math.floor(Math.random() * 16777214) + 1)

bot.channels.get('552674443131093002').send({voteEmbed});
}?

amber fractal
#

I may be wrong I think I'm too tired mmLol

sinful lotus
#
const tag = await _fetch_user(vote.user)
console.log(tag)

just leave this on your on vote

empty owl
#

ok

sinful lotus
#

so that I can debug easier

empty owl
#

ok

#

const express = require("express");
const app = express();
const fetch = require('node-fetch');
var HttpProxy = require('http-proxy')
app.get("/", (request, response) => {
  console.log("Ping received!");
  response.sendStatus(200);
});
const Discord = require("discord.js");
const bot = new Discord.Client();
// listen for requests :)
const listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);
});

const DBL = require('dblapi.js');

const http = require('http');


const server = http.createServer(app);







const dbl = new DBL(process.env.DBLTOKEN, {  webhookAuth: 'dblauthorizationcodehou', webhookServer: listener });
dbl.webhook.on('ready', hook => {
  console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
  console.log('Ready! Webhook running at /dblwebhook')
});
dbl.webhook.on('vote', async vote => {
  const tag = await _fetch_user(vote.user)

  console.log(tag)


});
    async function _fetch_user(id) {
        const req = await fetch(`https://discordbots.org/api/users/${id}`, {
            headers: { authorization: process.env.DBLAUTH }
        })
        const user = await req.json()
        return user.username + '#' + user.discriminator
    }

sinful lotus
#

@amber fractal yes the little lib handles that for you and u get the user+tag already

#

ok try to fire it up again

empty owl
#

undefined#undefined

sinful lotus
#

hmm ok wait a sec

#

lemme use my linter at that code

#
async function _fetch_user(id) {
    const req = await fetch(`https://discordbots.org/api/users/${id}`, {
        headers: { authorization: process.env.DBLAUTH }
    })
    const user = await req.json()
    console.log(user)
    return user.username + '#' + user.discriminator
}

@empty owl could you replace the _fetch_user with this

empty owl
#

{ error: 'Unauthorized' }

undefined#undefined

sinful lotus
#

your dbltoken is wrong

#

thats why it doesnt work

empty owl
#

oh

#

like which token

#

the dbl token

#

or the bot token

sinful lotus
#

the DBL token you use for server count posting

empty owl
#

oh

#

IK

#

i did the auth rather the token

sinful lotus
#

it should be the token

empty owl
#

this stuff

#

  avatar: 'cd2fe3bf8bdde55b97a7c5660e172286',

  id: '345349646253817857',

  username: 'bobthemoose',

  defAvatar: '0e291f67c9274a1abdddeb3fd919cbaa',

  admin: false,

  webMod: false,

  mod: false,

  certifiedDev: false,

  supporter: false,

  social: {} }

bobthemoose#2228```
sinful lotus
#

there thats your tag

amber fractal
#

That's the user object

sinful lotus
#

bobthemoose#2228

empty owl
#

ok now what do I do

#

how do I input it

sinful lotus
#

thats already the user

empty owl
#

into a embed or something

sinful lotus
#

the const tag is the user already

empty owl
#

oh

amber fractal
#

His lib thing return the tag

#

returns*

empty owl
#

so like tag is the stuff?

sinful lotus
#
console.log(user)

just remove this on _fetch_user so it wont flood

amber fractal
#

the tag is const tag