#development
1 messages · Page 474 of 1
this is C++ meme but relevant lmao https://cdn.discordapp.com/attachments/464603014691291166/473235272755314689/image.jpg
lmao
Ok so Javascript people:
To make my bot say something when it joins a new server, would I do something like:
client.on('guildCreate', guild => {
Or would I do something different? I'm not really sure how to do this
i mean
as long as thats the right action
which it should
i tihnk you're fine
thing is i think .defaultChannel is read-only
i also think its deprecated
dont hold me to that
so it might be funky
maybe just pming the owner some stuff
I think it's systemChannel
I know that but whats the one that we should use
loop through channels the bot can post to and get the first one
it does
and pm the owner
That would be to much work especially if the bot gains servers fast
what would be
Sending pms to the owner
But that's the thing
I don't see my bot climbing that fast
maybe
10 servers a day but like 18 servers first day
and people hate being dmd by bots
True
I would cycle through the channels and see which one the bot can send to first
What's the command to do that
York made a tutorial on how to do it
or dont send a message on join
thats an option u know
like
they invited the bot
I want the message thoygh
do u think they are gonan need a welcome message
though
theres a good way
Oh cool
an organized command hierarchy
where commands are broken into sub categories
so that it would be easier to find commands
that are related
var mail = require('mail').Mail({
host: client.config.mailer.host,
username: client.config.mailer.address,
password: client.config.mailer.password,
});
mail.message({
from: client.config.mailer.address,
to: ['root@mrsheldon.me'],
subject: 'Hello from Luki'
})
.body('Hellooooo Thereeeeeeeeeee')
.send(function(err) {
if (err) throw err;
console.log('Sent!');
});
(node:21828) [DEP0010] DeprecationWarning: crypto.createCredentials is deprecated. Use tls.createSecureContext instead.
(node:21828) [DEP0064] DeprecationWarning: tls.createSecurePair() is deprecated. Please use tls.TLSSocket instead.
oof
help please 
this is for any kind of development
ask a mod
ur in the channel topic
nou
ok
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
const { RichEmbed } = require('discord.js')
module.exports.run = async (bot, message, args) => {
let embed = new RichEmbed()
.setTitle("Error")
.setDescription("Could not find that user.")
.setColor(0xff0000);
if (args[0] == "help") {
message.reply("Usage: $dm <user> <message>");
return;
}
let dmMember = message.guild.members.get(message.mentions.users.first().id || args[0]);
if (!dmMember) return message.channel.send(embed);
else{
const args = message.content.slice(config.prefix.length + 3).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const mention = message.mentions.users.first();
const mentionID = mention.id;
client.fetchUser(mentionID) .then(user => user.send(args));
}
}
module.exports.help = {
name: "dm"
}
this has an error
the command is used like this:
$dm @wide ruin message
and yes, 3 bots dmd me
Perhaps knowing the error could help us help you
one second
`module.js:487
throw err;
^
Error: Cannot find module './config.json'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/app/commands/dm.js:4:16)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)`
it says error: Cant find module ./config.json
You don’t have a config.json in that path
Show your bot folder
./ only refers to the current folder, I’m assuming your config.json is not in the commands folder
You’ll probably get an error in your main bot file
`(node:17388) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Request to use token, but token was unavailable to the client.
(node:17388) [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.`
Told ya
so how can i fix it?
Move your config.json back to your root path and change the ./config.json to ../config.json afaik
gtg sorry
ok
Do numbers come before or after in sorting? Like, would it go 8ball, a_command, b_command or a_command, b_command, 8ball, or such?
numbers then letters
Alright, thanks. 😄
Weird question here, if I type +user @username i get the data for that user, but if i use @Koshi user @username i can only get the data for my bot/Koshi, how do i stop it from doing this?
its getting the first mention
if it uses the mention prefix make it get the second mention
how can i make a var work on each file?
so i set it in one file
and send it in another
(d.jd)
hey pineapplefan
also before you say anything else
yeah?
Thing is I don't know how to check if the mention prefix is being used @knotty steeple
i decided against making the command
oh ok
@karmic blaze how do you check if someone uses a prefix
with what
show ur code
what i said earlier
how can i make a var work on each file?
so i set it in one file
and send it in another
(d.jd)
First lines of my message event:
const { prefixes } = require('../config');
module.exports = async (client, msg) => {
const prefix = prefixes.find(pre => msg.content.startsWith(pre));
if (!prefix || msg.author.bot || !msg.guild) return;
...
(prefixes is an array, prefixes: ['+', '@random depot '],)
you mean like
so check if prefix is = '@random depot '
how to make bot make its own code? @wide ruin
no
Alright, I'll try pass it through and check.
use the same var in a different file
global variables iirc
ok
use module.exports and pass them in a function
what he said
module.exports(var name)?
no
how then
look at the docs for modules
idk look around
i cant see modules anywhere
module.exports.hmm = true;
the var is called hmm
is that right @knotty steeple?
wdym?
Sort all guild members by join date in a list/array and then get the certain member's position
That.. sounds hard, lol
Python has sorted() and <list>.sort()
no I mean I remember doing that with shiramine bot
no details doesnt really help
he's basically "hiring" people, or looking for collaborators
yes but what is this "big project" about
it's like you're interested
Im working with the spotify api.. I have the endpoint and have created the app but have no Idea how to get the token.. I only have the client secret and the client id
apperently theres this post request to get the token? I have no idea tbh
apperently you need to use an endpoint like this to get the token for the app? https://accounts.spotify.com/api/token
This is the endpoint Im trying to get btw https://api.spotify.com/v1/playlists/2yPnp0T86RmpNIQ07AkBQC
Is Possible create a Bot WebDashboard, if it possible contact me in DM
ofc it's possible
You help me?
@topaz fjord
Is Possible create a Bot WebDashboard, if it possible contact me in DM
Could someone help me make my bot play audio in a voice chat? I've tried using different methods from the Discord.js website and none of them have worked.
@shell blade you mean music?
Just audio files.
For a soundboard.
I've tried using this, but it didn't work.
const broadcast = bot.createVoiceBroadcast();
message.member.voiceChannel.join()
.then(connection => {
broadcast.playFile('https://cdn.glitch.com/864c9828-b89f-4db5-8f87-89af38495227%2Fnot_to_be_racist.mp3');
const dispatcher = connection.playBroadcast(broadcast);
}).catch(console.error);
These examples haven't been working.
https://github.com/discordjs/discord.js/blob/master/docs/topics/voice.md
[2018-08-31 16:01:26] TypeError: fn is not a function
[2018-08-31 16:01:26] at Map.map (C:\Users\fazin\OneDrive\Documents\Coding\Bots\Discord\Daylight\node_modules\discord.js\src\util\Collection.js:263:47)
[2018-08-31 16:01:26] at Map.store.(anonymous function) [as map] (C:\Users\fazin\OneDrive\Documents\Coding\Bots\Discord\Daylight\node_modules\discord.js\src\util\Util.js:454:23)
[2018-08-31 16:01:26] at module.exports.run (C:\Users\fazin\OneDrive\Documents\Coding\Bots\Discord\Daylight\commands\Information\user.js:58:41)
[2018-08-31 16:01:26] at module.exports.runCommand (C:\Users\fazin\OneDrive\Documents\Coding\Bots\Discord\Daylight\node_modules\klasa\src\monitors\commandHandler.js:91:106)
[2018-08-31 16:01:26] at <anonymous>
[2018-08-31 16:01:26] at process._tickCallback (internal/process/next_tick.js:188:7)```
thonk
It's part of d.js
How can i fix it?
here is the code
let user;
if (!getUser) {
user = msg.author
} else {
user = getUser
}
let member = msg.guild.member(user);
let status;
if (user.presence.status == "dnd") {
status = "Do Not Disturb"
} else if (user.presence.status == "online") {
status = "Online"
} else if (user.presence.status == "idle") {
status = "Idle"
} else if (user.presence.status == "offline") {
status = "Offline"
}
msg.channel.send({embed: {
title: `${user.tag} user info`,
fields: [
{
name: 'Username and Discrim',
value: user.tag,
inline: true,
},
{
name: 'Status',
value: status,
inline: true
},
{
name: 'Joined Discord',
value: moment.utc(user.createdAt).format("dddd, MMMM Do YYYY, HH:mm:ss"),
inline: true
},
{
name: 'Roles',
value: member.roles.map().join(' | ')
}
]
}});```
oh wait
you cant leave it empty like that
what
member.roles.map().join(' | ')
ye i noticed
for some reason i changed it before i came here, worked, and then reverted back
i may have it ctrl z
by accident
does anyone have any idea how can i add 20 seconds cool down before a user gets xp on each message?
async def on_message(self, message):
author = message.author
await self._set_levels(author)
await asyncio.sleep(20)
try:
self.data["user"][author.id]["total_xp"] += int(randint(10, 15))
dataIO.save_json(self.file_path, self.data)
except:
pass```
this is my codes
Probably make a list and append user ID there and then check if the user ID is in there
add a lastxp timestamp to his entry in the database
and on message check if difference between saved timestamp and current timestamp is bigger than 20 seconds, if it is, add xp and change the timestamp
(:
did you just copy +paste your site css
mhm
css is not just css, css is always css+html. they work together
that wont work
oh
so you have to code specific css for the html of the website
im not sure
can someone tell me whats wrong with this code
async def state(ctx,state= ""):
"""Shows information about a state."""
if state == "":
await bot.say(":x: | Please Specify a state")
if state == "California":
color = ''.join([random.choice('0123456789ABCDEF') for x in range(6)])
color = int(color, 16)
embed.add_field(name= "Admission to Statehood", value = "September 9, 1850 (31st State)")
embed.add_field(name= "Area", value = "163,707 sq.mi (423,999 sq.km.)")
embed.add_field(name= "Capital City", value = "Sacramento")
embed.add_field(name= "Nickname", value = "Golden State")
embed.set_footer(text= "{} | Requested by: {}".format(OceanConfig.BOTNAME, ctx.message.author))
await bot.say(embed = embed)```
it keeps giving me this error
Traceback (most recent call last):
File "C:\Users\xmoreno\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
ret = yield from coro(*args, **kwargs)
File "C:\Users\xmoreno\Desktop\Ocean Main.py", line 47, in state
embed.add_field(name= "Area", value = "163,707 sq.mi (423,999 sq.km.)")
NameError: name 'embed' is not defined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\xmoreno\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:\Users\xmoreno\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 374, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
File "C:\Users\xmoreno\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 54, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'embed' is not defined```
you didnt define embed
im a little new to this, what does that mean
did you even learn anything about python
name 'embed'; is not defined

\:emoji:
it's always a good practice to learn about a programming language first before heading to make something as large as a discord bot
that's a unicode, those don't have ids
thats not an emoji lel
it is?
emoji IDs are only available in custom emojis
How did you get that?
magic
put \ in front
/
Ah ok. Thanks.
i just said what you had to do lmao
also, @proven surge i dont know python, but im pretty sure your problem is this ```js
color = int(color, 16) // program: ok so color means int(color,16)
embed.add_field(name= "bla", value = "bla") //program: ok so embed is... wait what is an embed? you didnt tell me what an embed is yet
back slasj
@knotty steeple I know, I tried it with a normal emoji and thought it didnt work until they told me
lmao
@quartz kindle their problem is that they went adding fields before defining the embed, if it is even defined anywhere
thats exactly what i said, in noob language
yes, I don't understand noob language
\✅
😄
That spike in Memory when accessing an API cant be good...
Should I increase RAM?
only 20MB RAM?
oh
looks like
I'm blind
True true
lel
thanks @quartz kindle, i figured it out
you could have just said add embed=discord.Embed()
😛
that was for you to find out ;)
but thanks anyway lel
so now you know what the error means if it happens again
we dont want to spoon feed you
yes
How do I make the text not to go off the image, I am using Canvas.
use measureText
with this you can measure the length of the text before drawing, and adjust it accordingly
unfortunately there isnt a simpler solution
you have to break down the text yourself
for example, use split(" ") to get an array of words, and add each word to the sentence until it reaches a cap, which you can define by character length, or by measuretext length
then you have to finish the line, and create a new line
here's an example
To wrap text with HTML5 Canvas, we can create a custom function that requires the canvas context, a text string, a position, a max width, and a line h
what he does in that example is exactly that, split sentence into words, create a new line, add one word at a time until it exceeds the limit, draw line, create new line with the exceeding word, continue
of course you have to move the Y coordinate to the next line as well
yeah, just trying and seeing how will it work
So I have a 8 ball command in d.js
You say $8ball <question>
I want a way to rig the answer
Like $8ball <message> &&outcome=<outcome>
The code I need is to remove everything up to <outcome>
And save just <outcome> as a var
How is that done?
How is it then
contains isnt a thing
Is it contents?
.includes()
Ah
uh ye, i think lol, i cant think rn
Thanks though
np
It didnt work
if(message.content.includes("&& outcome=") { was what I used
@west raptor
error?
huh
i dont see the issue?
The { at the end of the first bit had the error
can you give the full error?
Invalid syntax "{"
can you code block it
let result = Math.floor((Math.random() * replies.length));
let question = args.slice(0).join(" ");
if(message.content.includes("&&outcome=") {
}
else{
let ballembed = new Discord.RichEmbed()
.setAuthor(message.author.tag)
.setColor("#00ff00")
.addField("Question", question)
.addField("Answer", replies[result]);
message.channel.send(ballembed);
}```
wheres the ennding to thne else statement
Cut off
tfw you all cant see he is missing a )
O
and im suprised you didnt see that yourself
if(message.content.includes("&&outcome=")) {
}```
@knotty steeple sir im legally bling
same
or just slice it out
yea how would you do that
I'm not js dev I'm using pseudocode
Please can you translate it into code
ok then do it
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
This slices all after the prefix
But can I replace config.prefix.length with "&&outcome="?
Set the outcome of the 8ball
you could use Array.find
But custom things
args.find(x=>x.startsWith("&&outcome="))
How would that fit into the code?
why do you have to set the outcome of 8ball 
you want an argument that starts with &&outcome
that finds the argument
although separating question and outcome might get a bit hard
@queen sentinel, my discord bot (@ruby siren) got muted because it would respond to other bots.
This problem should be fixed.
Done 👍
So @inner jewel
I used your method
But outcome is "&&outcome=no"
How do I fix that part?
This is the last bit
Please help
.substring
you should learn to read the docs
I need help with something.. I am trying to make it so you can do !verify male or !verify female and it creates a channel were only the person that used the command and the owner and staff of the server can see the channel. Also I want it to send a message to that channel along with giving them the role and deleting the channel if the Owner or staff approves this person. Another thing, if 60% members have the Male verified role, it won't let anyone use the !verify male part of the command and only let females verify
I have the create channel down
and the perms
I just need the 60% thing done
Along with the !verify female or !verify male
store the amount of males and females somewhere per server
oh ok
then just store the 2 numbers in the bot config / whatever way you think is best
every time someone verifies, check if there is more than 60% majority
do you want the person to run the command more than once? or just one time and then lock the command from them
oh ok
They are not allowed to verify more then once ;p
the first thing you should do is this: when a person does !verify male/female, add 1 to the amount of males/females in a config somewhere
OH FUCK DELETE THAT
Its fine lol
and reset your token ASAP
I know there is a token
wot
you should probably do it now
like right now
meh
boi
uhhh alright
Its fine lmfao
¯_(ツ)_/¯
ok so when someone api abuses and gets you api banned and possibly get you account banned dont come crying to us
oh
ok
good
Yea
lmfao
Anyway
{
"token": "",
"prefix": "!",
"Male": {
},
"Female": {
}
}
Here it is
without the token
Also
The bot app is not on myaccount
xD
It is on the person that wants the bot's account
Bot*
I told them to reset the token though
Anyway is that how you do it?
in the male / female area's store the user id
fyi all deleted messages get logged in #265156361791209475
and if the user leaves, then remove the id
Well fuck
Yea I guess
I told my vlient to reset it
Client*
I hope I set up the Male and Female thing right in my config o.o
Well whoever made the bot leave the only guild it was in
That is cool
Glad they didn't uck the server up though
thats what happens when a token is leaked 
"Male": {
},
"Female": {
}
}
Here is the part of the json
that has the male and female thing set up
So the ID's go into those brackets and hopefully get recorded in there
you'll want an array for that
Oh?
unless you need to map other data to the ids
Ah
yes
Ok
Thank you
const Discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
guild.createChannel('new-general', 'text')
.then(console.log)
.catch(console.error);
}
module.exports.help = {
name: "verify"
}
Also this is what I have for creating the channel
I am not sure if this is write or not
I made this example
before I got to far into it and it was wrong
so i have a random number generator that posts 3 embeds after the number is generated
all of them are literally identical besides the message
except
the 2nd of the 3 sometimes won't print out
so i have one Green, one Blue, one Red. The Green posts, then Blue, then Red. (Red sometimes lags a little but that's okay). Sometimes, it will just print Green - Red
ommitting the Blue
anyone know why?
just a sec
message.channel.send({embed: {
color: 3066993,
description: "You rolled a **" + random + "**."}})```
if (random / number <= 0.2) {
message.channel.send({embed: {
color: 1752220,
description: `Battle Damage: \n Critical Miss. Using a bow? Subtract 1 arrow from your inventory.`
}});}
else if (random / number <= 0.3) {
message.channel.send({embed: {
color: 1752220,
description: `Battle Damage: \n Flimsy Hit. 50% of Base Damage.`
}});}
else if (random / number <= 0.6) {
message.channel.send({embed: {
color: 1752220,
description: `Battle Damage: \n Weak Hit. 75% of Base Damage.`
}});}
else if (random / number <= 0.8) {
message.channel.send({embed: {
color: 1752220,
description: `Battle Damage: \n Hit. 100% of Base Damage.`
}});}
else if (random / number <= 0.8) {
message.channel.send({embed: {
color: 1752220,
description: `Battle Damage: \n Powerful Hit. 125% of Base Damage.`
}});}
else if (random / number <= 0.8) {
message.channel.send({embed: {
color: 1752220,
description: `Battle Damage: \n Critical Hit. 150% of Base Damage.`
}});}```
if (random / number <= 0.4) {
message.channel.send({embed: {
color: 15158332,
description: `Enemy Damage: \n Miss.`
}});}
else if (random / number <= 0.6) {
message.channel.send({embed: {
color: 15158332,
description: `Enemy Damage: \n Weak. Base Damage.`
}});}
else if (random / number <= 0.8) {
message.channel.send({embed: {
color: 15158332,
description: `Enemy Damage: \n Hit. 300% of Base Damage.`
}});}
else if (random / number <= 1) {
message.channel.send({embed: {
color: 15158332,
description: `Enemy Damage: \n Critical Hit. 500% of Base Damage.`
}});}```
could you instead use hastebin?
oh ok
hi
const Discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
channel.delete()
.then(console.log)
.catch(console.error);
}
module.exports.help = {
name: "close"
}
Would that work as
deleting the channel
the command is used in?
So no
I forgot to define channel
~<
I also don't remember how to define channel for something like that
My friend told me but my memory is shit
what channel are you deleting
I am deleting the channel the command is used in..
Also
I just done this
Someone helped me with part of it
const Discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
if(your command arguments here){
<Message>.channel.delete()
.then(console.log)
.catch(console.error);
}
}
module.exports.help = {
name: "close"
}
That is why it says
your command arguments here
are you using args
if you can't understand that code and fix it, you should learn js and your lib before making a public bot
<Message> would be your message object
Seeking help is one way of learning as you can learn from what the other person says
So sorry for learning in my own way :3
Ima take a break
so i generate a random number, and after that it prints 3 embeds. however, the 2nd one (Blue) sometimes doesn't print. Also the program sometimes lags, if that could cause it?
anyone know why?
https://pastebin.com/2cm5VNxz
could someone help me figure out how to get the authorization token to "https://api.spotify.com/v1/playlists/2yPnp0T86RmpNIQ07AkBQC"
I have the user ID and the client secret I need to post something to an endpoint called "https://accounts.spotify.com/api/token" but Im not sure how to do it
Hey- why is this always returning -1?
I'm trying to get the join position of a user.
-1 means it was not found
also, instead of indexof(find), just use .findIndex()
@vernal basin blue doesnt print anything if the random number is above 0.8
you dont have anything for that
@earnest phoenix to POST something, means to send an HTTP request using the POST method
you can use libraries such as snekfetch, request, node-fetch, or use node's internal http functions
Think you tagged the wrong person there @quartz kindle :3 but okay, uh, how would i use .findIndex()?
I know
check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
const snekfetch = require('snekfetch')
const config = require('./config.json')
//Fetching the playlist from the spotify api
const credentials = {
client: {
id: config.client_id,
secret: config.client_secret
},
auth: {
tokenHost: 'https://accounts.spotify.com',
tokenPath: '/api/token',
authorizePath: '/authorize'
}
};
snekfetch.post(credentials.auth.tokenHost)
``` currently trying it (this is unfinished code)
@earnest phoenix How are you POSTing it?
Ohhh
You can use .set('Authorization', ' ... ')
thats not how you do it
i'd like to remind that snekfetch is deprecated and shouldn't be used 
i mean it works fine for now
It works fine as .-.
i use request instead
@earnest phoenix you dont need any credentials object
@heady zinc ur deprecated
why dont I?
use node fetch
I need the bearer token
according to the spotify api
it should be something like
headers: {
'Authorization': 'Bearer ' + accessToken
},```
idk if im looking at the right place tho
you are
but I need to get the "accessToken" before I can use it
I only have the clientID and the clientSecret
you'll need to set up an oauth callback for that
afaik
your access token will be expiring hourly as well, you'll want to store a refresh token alongside it
wdym
hm
so
const credentials = `${config.client_id}:${config.client_secret}`
snekfetch.post("https://accounts.spotify.com/api/token").set('Authorization', credentials).then(r => {```
and I'll need an redirect url
so I need to use express too I guess?
I really dont fucking know how to get this token ugh
the problem is
You do Prompt your user to a webpage where they can choose to grant you access to their data.
You get An access token and a refresh token.
its oauth2
they need to click on your link
to give you the token
I dont want oauth2 smh I just want to get a playlist with my "app" on spotify
then you're using the wrong authorization
okie
https://api.spotify.com/v1/playlists/2yPnp0T86RmpNIQ07AkBQC``` Im trying to get this
what token do I use
this is what you need
Client Credentials Flow
The Client Credentials flow is used in server-to-server authentication. Only endpoints that do not access user information can be accessed. The advantage here in comparison with requests to the Web API made without an access token, is that a higher rate limit is applied.
You do Login with your Client ID and Secret Key.
You get Access token.
;-; thats exactly what I was looking at too
before I looked at the bearer token and my brain went oh I must need this one
if i understand correctly
POST must have {"grant_type":"client_credentials"}
and Header must have "Authorization" : "Basic <base64 encoded client_id:client_secret>"
I'm not sure where to put this but I have this so far now ```
onst host = "https://accounts.spotify.com/api/token"
snekfetch.post(host, ).set('Authorization', credentials).then(r => {
}
oof thats const btw
credentials is going to be the base64 string
lemme check if it works
is there any lib that is in node that can convert base64
or in discord.js or something
Don't need a lib. It's built into JS
atob() and btoa() are base64 operations
so I can do something like base64 = require('btoa') or is it just a built in function
fuck im a noob nvm
its built in into js itself, not node
Show code
const credentials = btoa(`${config.client_id}:${config.client_secret}`)```
that isn't nodejs
my node is fucked? 
oh
The 'btoa-atob' module does not export a programmatic interface, it only provides command line utilities.
If you need to convert to Base64 you could do so using Buffer:```
stack overflow saves the day
nodejs allows you to base64 encode stuff with Buffer.from('stuff').toString('base64')
oof wtf (node:8828) UnhandledPromiseRejectionWarning: Error: 415 Unsupported Media Type
media lol wut
hmm
what do you have now?
these `
i mean, the whole code
const credentials = Buffer.from(`${config.client_id}:${config.client_secret}`).toString('base64')
const host = "https://accounts.spotify.com/api/token"
snekfetch.post(host).set('Authorization', credentials).send({"grant_type":"client_credentials"}).then(r => {
console.log(r)
})```
is the error coming from Buffer, or is it coming from snekfetch?
let test = "hello";
let other = " world";
Buffer.from(`${test}:${other}`).toString("base64")``` worked for me
according to the spotify docs, the authorization header should be "Authorization" : "Basic <base64 encoded client_id:client_secret>"
oof its coming from snekfetch
so in your case: "Basic "+credentials
still says it
const credentials = Buffer.from(`${config.client_id}:${config.client_secret}`).toString('base64')
const host = "https://accounts.spotify.com/api/token"
snekfetch.post(host).set('Authorization', `basic ${credentials}`).send({"grant_type":"client_credentials"}).then(r => {
console.log(r)
})
maybe Basic with capital B?
nope :((
I guess snekfetch is shit? 
tbh Im probably doing something wrong
lul
snekfetch may be deprecated, but it is still fully working 
ok
like this?
snekfetch.post(host).set('Authorization', `Basic ${credentials}`).send({"Content-Type":"application/json", "grant_type":"client_credentials"}).then(r => {```
set('Authorization', Basic ${credentials}).set("Content-Type":"application/json").send()
I tried ://
snekfetch.post(host).set('Authorization', `Basic ${credentials}`).set("Content-Type":"application/json").send({"grant_type":"client_credentials"}).then(r => {
^^^^^^^^^^^^^^
SyntaxError: missing ) after argument list```
Its pointing at the "Content-Type"
oof should it be a comma
I changed it to a comma
and it worked but gave me an error again with the media type
comma im guessing instead of :
it worked wow
I got a big buffer and a body cool
thank you so much wow
finally, now i can sleep
oof what time is it for you
only 11pm, but im not a nightcore person
okie goodnight fam
Is there a way to get connections on a user's profile? I'm guessing it's for user bots only, I also am to lazy to read the docs
I'm not really sure what /[ ]+/ means, but I'd guess that args would become an array, in which case you can use args[0] to get the first argument, args[1] to get the second, etc.
also keep in mind that there's frequent OutOfRangeException errors with that, so before accessing args[1], make sure that args.length > 0 is true
or args.length > 2 is true before accessing args[3], for example, and etc.
Why does:
var sender = message.author;
message.channel.send("@everyone\n"+`**Important message from ${sender}:**`);
message.channel.send(`${argsannounce}`);```
return
a , infront of it?
Is this JavaScript?
yes
It returns a , in front of the first message? before the @everyone?
ill show u
alrighty
try replacing your first line with var argsannounce = message.content.replace("!announce ", "");
um
the problem there is that if someone uses !announce without anything after it it might break but I'm not 100% sure how JavaScript handles it so idk
the problem there is that you're creating an array from the string !announce Announcement, splitting it by !announce, which creates two items in an array, which is a completely empty string and Announcement- you're asking it to post the full array, so it posts the first item, then Announcement, surrounded by commas to separate it, so it outputs , Announcement
It handles it fine, thanks for the help and explanation!
ok
seems the regex string [^0-9a-zA-Z]+ works pretty well, just stole that from google 
use \W
"A word character is a character from a-z, A-Z, 0-9, including the _ (underscore) character."
so let me break this down
if \W is a-z, A-Z and 0-9
then why the fuck are you keeping 0-9a-zA-Z in your regex
and why is \W out the front

https://regex101.com/ to test and explain regex
pretty sure that works for what u wanted
oof there did they go
Sorry if this is an easy answer. I'm stumped
How can I go about adding a role to active chatting users, and timeout like 10 minutes after if they stop being active?
like only give it to people who are constantly active for like 5 mins straight
if that makes sense
can somebody help
i am making a new bot
but this time in javascript
yep
can someone help
wdym by "help"
i dont get how i make a !help command
what
oof what lang did you make your bot in before?
Discord Bot Maker Program

oh
lmaooo
Do you know javascript?
a bit
Or python?
you need a command handler
Kush shh
😦
lul
I have a command, event, config and permission handler oof
if (message.author.bot) return;
let prefix = "!";
if (message.content.indexOf(prefix) !== 0) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "help"){
...do something
}
and you can follow the if statement on the bottom for other commands
ill break it down
sec
if (message.author.bot) return;
This is just so the bot doesn't respond to itself
let prefix = "!";
Your prefix
if (message.content.indexOf(prefix) !== 0) return;
No prefix? Don't respond.
const args = message.content.slice(prefix.length).trim().split(/ +/g);
Splits the string up into arguments. So you can access it later by args[0,1,2,etc..]
const command = args.shift().toLowerCase();
Converts the command or args[0] to lower case
if (command === "help"){
...do something
}
Your if statement for commands.
there
enjoy
oof
amazing command handler 10/10
Yeah actually thats a good start
once you get more advanced you'll get into things like modular command handlers
yeh i only gave him that because he's practically new
its easier to have stuff in 1 document
than thrown all over the place
use an object with each command and check the key
no if statements and reloafable commands
does somebody have a !help embed command in js that i can customize
u can learn js. and make one urself
no 


un bad in js

We won't spoon feed you. You need to learn
and im bad at some things
Check out embed documents
the solution is learn
Look up
"discord.js embed"
not ask for spoonfeed
Now. I have a question for you guys

ok
I wanna make a role where whenever the user is talking constantly for a certain amount of time (like 5 mins) they'll get a role.
It'll stay on them unless they stop talking. Which after 10 mins of not talking it'll be removed
Basically an activity role
Discord.js
i can make that with DISCORD BOT MAKER
that would be cool
lmfao
discord bot maker

I dont want discord bot maker lol
probably a bad idea since u will hit ratelimits for role, but you could store like the number of messages a person sends, then every 10 mins give people with a certain number of messages a role, and reset the coubt
Nah rate limits are fine
That'll only be a rate limit unless it's constantly changing
it would be 😂
is it a global bot?
No
oh then you should be fine
i have another bot thats on 24k servers
but im not going to add him to that
add that to him *
the bot token would be banned really quick
@earnest phoenix you're bad at js lmao
not anymore
wanna join my test server
i made a bot in visual studio code
@serene cobalt
still adverting a server
not
how do i let the bot send 2 lines in an embed]
if i use enter it will give an error
\n
?
What happened to you being good at js?
\n is newline
{
name: "Moderation",
value: "``!kick`` - kicks an player from the server."
}
],
timestamp: new Date(),
footer: {
icon_url: client.user.avatarURL,
text: "Absolutech"
}
}
ow thx
pff
what
if xp < 100:
level = 1
elif xp < 250:
level = 2
elif xp < 475:
level = 3```
am i doing this right 
No
@earnest phoenix
imo you should
base how levels off
a exponential systems
so like for my bot
first 10 levels is the level * 100
thats how much exp you need to level up to the next level
then after level 10
you multiply the previous level's exp by 1.1
ill show the function
what do you mean
users start off as level 0
right
so you need 100 xp to level up to level 1
then you need 200 to level up to level 2
etc
until level 10
right
so at level ten
itll be however much exp you need for the previous level
- 1.1
so at level nine you need 1000
so at level 10
itll be 1000 * 1.1
which is 1100
yep
yea
but
its a bad idea to hard-code stuff like exp
dont hard code exp dude
thats just not good practice
the alg doesnt really matter that much as long as you scale how much exp users earn accordingly
yep
alright so I need to refresh a token for my application once every 10 days
i was considering a scheduledexecutor but im not sure if thats the best solution?
I wont get any sort of notification when it runs out or whatsoever by the server
technically i can change the 10 days to anything between 1ms and 10 days if that makes a difference
something java based if anything has any suggestions
Keep track of when you last refreshed token and make sure token is valid each time you need to use it
problem is i dont need to use it i get notified with events for the duration i pass it on creation @neon swift
so theres no indicator for checking

So you need to auth against their webhook instead of them authing against your server??
Hey i need help setting up commands and things for a bot on a server im running
no 😩
do you want to create your own bot?
ive got the bot made just need things for it to do and how to make it come online
what do you mean with "got the bot made"?
you mean going to the discord dev website and creating a bot account?
or actually coding something?
can you tell i'm new at this? haha
yes
im gonna tell how you bots work
you create a bot account, which will give you an id to login with.
you create/code a program that will use the id to connect to discord.
your program receives messages from discord, does actions with it, and returns messages to discord
the bot will be online while this program is running in your computer
right
do you have experience with any programming language?
😖 not really
then your first step is to learn a programming language
we just needed a bot and we didnt wanna use a premade one
good languages for beginners are Python and Javascript
ah ok
study a language for a bit first, until you understand it more or less, then come back to attempt a bot
ok
otherwise you'll be running in circles having no idea what you're doing
good luck!
Javascript is probably the best to learn for discord bot making. It has the most people willing to help you
Py is also good
Yeah, but it has like half the share of bots made
yeah probs sound like a tool but is there money involved?
There are free IDEs
No, unless you you want a VPS
Oh yeah, you need to host the bot so you would need to pay 4$ a month for a cloud server
Or self host
or host on your own PC if you have internet and stable electricity
ah ok

