#development
1 messages · Page 969 of 1
@vale garden https://lmgtfy.com/?q=javascript+function+syntax
For all those people who find it more convenient to bother you with their question rather than search it for themselves.
lmao that is my new favourite site
.
-dotpost
Please do not post dots to clear your messages/get attention. It adds absolutely nothing to the conversation and just causes spam.
If you need to get attention, then say hello everyone. If you need to clear your messages, then press the Esc key. If you do not follow these instructions you will be muted.
im getting an error
and what could it be, i wonder...
function before execute? 👀
@vale garden https://lmgtfy.com/?q=javascript+function+syntax
@green yarrow
For all those people who find it more convenient to bother you with their question rather than search it for themselves.
multi is a baboon, if you ask a question, you need to actually listen to the responses.
ok but did you read what i said
are you 12
see?
Rule 1
ok i got that
you have to define it like other properties name: value
you didn't notice the difference, probably
are they arrow functions?
probably
module.exports = {
name: 'bal',
description: "for check a user's balance",
aliases: ['balance', 'cash'],
execute(message, args) {
command that perfectly works
oh gosh
those don't work
that shouldn't work
A JSON consists of key and a value
ok ruby you do this
no
yea
..no
no
wdym no
didn't work
bruh i have proof
no you don't
nope
You are creating a JSON that can't work when there's only a key or a value present
but it does
In this case you are not creating a valid JSON
Probably because you didn't restart your code to apply the change
if it was working, you wouldn't be here.
are you 12
a JSON only consists of key: value structure and you cannot do
{x: y,
myfunction()}```
what is your point
actual question not rule 1
crap
that's not really json but still
no
it doesn't
wdym by it doesnt
flaze I'm not a JS dev, cut me some slack 
i just showed you
anyone know how to get items from an array in mongodb for discord.py?
have you tried reading the docs?
can you link me the docs ive searched everywhere
Dear lord what
that's a mistake in the docs then
What do you call {x: y} in JS
object 
Could you be more precise please
no it doesn't
this isn't getting anywhere
thanks ecmascript
that's the point, I hope they actually try the solution given to them, or leave.
kill me
that is what i did
Exactly, no clue why peeps are saying it's wrong or whatever
i was definitely in the wrong on this one lul
hey fellow interneters
Imagine having it work on your machine and somebody else tells you it doesn't
i never knew that was added in es5 lol
me neither
execute: function (message, args) {
message.channel.send('Pong.');
},
Same thing
anyone know why I'm getting a error? it says expected ',' but idk where to put that. ;-;
oh
you fucked up
What is that break doing there?
Who are you talking to @pure lion
no idea
oh I coppied the embed thing from a command-
@still merlin })
I removed it
Yep, too many closing }
yo im back
yo
ask
doesn't work
lol why am i getting an error

idk, you won't show me what the error or code is
Probably due to incorrect code
i did
oh
Let me quickly consult my crystal ball
i showed both the code and error
well then
Probably due to incorrect code
@hasty sparrow
^ biggest understatement over
wait one sec
const Discord = require("discord.js"); const client = new Discord.Client(); const Eco = require("quick.eco") const eco = new Eco.Manager() let shop = new Eco.ShopManager() module.exports = { name: 'buy', description: "for buying items in the shop", execute(message, args) { let water_bottle = args[0]; let add = shop.getItem(message.author.id, "water_bottle"); let subtract = eco.removeMoney(message.author.id, 750); if (!args) return message.reply("Please enter an item to be bought like this for example:\n2t!buy water_bottle") if (args[0]) return message.reply(`You have bought a ${getItem.item.Name} for ${removeMoney.amount}`) } }my code ^
and im getting this errorexecute(message, args) { ^^^^^^^ SyntaxError: Unexpected identifier
@vale garden
this
sometimes .com is broken. if that's the case you have to use hasteb.in
or like anything else that's not pastebin
@vale garden Try using https://discordapp.com/channels/264445053596991498/272764566411149314/720624980571717682 instead
oh that's me
wow who knew
wait
Which version of Node are you using?
what
{
node: '12.16.3',
v8: '7.8.279.23-node.35',
uv: '1.34.2',
zlib: '1.2.11',
brotli: '1.0.7',
ares: '1.16.0',
modules: '72',
nghttp2: '1.40.0',
napi: '5',
llhttp: '2.0.4',
http_parser: '2.9.3',
openssl: '1.1.1g',
cldr: '36.0',
icu: '65.1',
tz: '2019c',
unicode: '12.1'
}
yeah es5 should work then
no
its probably
something wrong with the command itself
cuz i pretty doubtful writing it
Is here anyone who can help me setting up shards?
I have created shards but i need help in getting data from all the shards like users, channels by id and sending embeds
@earnest phoenix lang?
js
I use ubuntu to host my bot, and I tried using the DBL webhook thing to get votes
but... the vote event doesnt trigger
and the ready event triggers soo hmm
can it be the ubuntu firewall blocking it, do I need to allow something?
Fr
hey does anyone know the html class for this
https://gyazo.com/41fe1d219dc83107c5997c78fe5f7857
You need the port open
@modest maple well, the thing is.. it opens when any service requires it
and it is open according to some werbsite which checks it
🤔
but.. hmm maybe imma enable on vps-side too
a FR really shouldnt do that
if it opens any port that a service wants thats very dangerous
do sudo ufw status
anyone know all the classes for the bot page
as editing mine ive done the bot-name and short description so far
wait i think ive figured it out
hello
i made a new bot to test a currency system
but i got this error
Error: ENOENT: no such file or directory, scandir './commands'
at Object.readdirSync (fs.js:872:3)
at /home/runner/DullSereneVolume/index.js:11:25
at Script.runInContext (vm.js:131:20)
at Object.<anonymous> (/run_dir/interp.js:156:20)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
You don't have a directory named ''commands'' @loud horizon
i enabled ufw lol
np
I get this error and idk what i would replace with the code.. any ideas? (SyntaxError: await is only valid in async function is the error)
the code that trys to make the mute role.
if(!muterole){
try{
muterole = await message.guild.createRole({
name: "SpiderBot Mute",
color: "#000000",
permissions:[]
})
message.guild.channels.forEach(async (channel, id) => {
await channel.overwritePermissions(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false
});
});
}catch(e){
console.log(e.stack);
}
}
I have tried serveral times
and asked my friends to vote..
and the vote event doesnt trigger
://
Did you open the required/correct port?
and after trying for about 2 hours, i am still unable to send an embed by getting a channel from shards ;-;
if i use normal text in code, it sends that text... but embed...
can anyone show me any example to send an embed to a channel by getting a channel from shrds?
shards*
the guide told you how to do that
i tried it
but still unable to send "embed"
i can send texts but i am not getting how to send embed
Do you know how to send an embed?
ofc i know xD
in bot without shards, i can easily do that...
but i am facing problem in shards...
i just added shards today
hi
because bot was facing ping issues and ppl suggested me to use shards
I'm guessing you don't know which guild has the channel you are looking for?
when i try to send normal text, it sends it... but in embed, i am facing problem
/home/runner/DullSereneVolume/index.js:52
bot.commands.get('test').execute(message, args);
^^^
SyntaxError: Unexpected identifier

im getting this
@earnest phoenix Show your code
const embed = new Discord.RichEmbed()
.setTitle("Suggestion!")
.setColor("GREEN")
.setTimestamp()
.setDescription("We got a new Suggestion!")
.addField("Suggested in Server:", message.guild.name)
.addField("Suggested by user:", message.author.tag)
.addField("Suggestion Details:", suggestion);
client.shard.broadcastEval(`
const channel = this.channels.get('${args[0]}');
if (channel) {
channel.send(embed);
true;
}
else {
false;
}`)
this is what i tried recently
someone help me plz
using args[0] (through that guide) and also using the id of server at it's place
channel*
not server :p
but still unable to send embed
someone hellp
send your code @loud horizon
djs v11 or v12?
const Discord = require('discord.js');
const keep_alive = require('./keep_alive.js');
const PREFIX = "t!"
const bot = new Discord.Client();
const token = process.env.DISCORD_BOT_SECRET;
const fs = require('fs');
bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
bot.on('ready', () => {
console.log('YOO boi im active lol LMAOOO');
console.log("Bot is ready with username: " + bot.user.username);
bot.user.setActivity(`I am a test bot for testing a currency system using my own database in only one server lol`, {
type: "STREAMING"
});
setInterval(function () {
var u, user;
for (u in bot.users) {
user = bot.users[u];
if (user instanceof Discord.User)
console.log("[" + u + "] " + user.username);
}
}, 10000);
});
bot.on('message', message => {
if (!message.content.startsWith(PREFIX)) return;
let args = message.content.slice(PREFIX.length).split(" ");
switch (args[0]) {
case 'test'
bot.commands.get('test').execute(message, args);
break;
}});
bot.login(token);
ronak
yes i am here xd
the guide is v12 now by default. did you switch to v11?
embed is undefined
yep i did
all right
meanwhile me waits for someone to send me a solution
channel.send(embed);
You aren't passing the actual embed
hmm
then... what should be it?
anyone know how to change button colours on top gg
ive changed most the info and colours
The same way you are passing args[0] I guess
and i totally forgot about making my top.gg bot's page look gud
i tried that as well xD
lemme try it again once
@earnest phoenix ive forgot how to change the buttons lolllllllll
Inspect element
well, i am new to top.gg xd about 3 days ago bot was added
got trending new bots #3 for a day then BOOM it disappeared from trending xD
@hasty sparrow ive looked in inspect element i got the class just i cant seem to change the box colour i can change the text know
}
.titleandvote{
-webkit-background-clip: text;
-webkit-text-fill-color: black;
background-color: ...?
tried that it dont change it
How could i make my bot not respond to prefix only ? He should respond to p!hello with wrong command but not to p! only.
nope still it is not working
Don't send a reply if no command is found
i got the worst error from google.... 429.... anyone that knows how to let proxies work? ;D
@hasty sparrow Yea. But my users should know they used a wrong commmand
ratelimit :^)
Then check if the message contains anything after the prefix
@hasty sparrow But how ? Im lost xd
then make it like that after return :
return message.reply("Reply goes here")
@clever tree
after returning, it will reply to the user whatever u want
@earnest phoenix .btn-orange has the colour (which isn't even orange, amazing devs)
@earnest phoenix Thats not really my problem but thanks too. I want my bot to not respond to prefix if nothing is after the prefix.
When you try and find the command, check whether the command name is empty, if it is, return nothing
if(!command.name) return message.reply("Reply goes here");
like this xd
now depends on what value u gave to "command" const tho
my friend just joined my server for a test. I have a logging method if you have a log channel yet it didnt log it.
logging command
client.on("guildMemberAdd", (member) => {
const channel = member.guild.channels.cache.find(
(ch) => ch === serverlogchannel
);
if (!channel) return;
let serverembed = new Discord.MessageEmbed()
.setTitle("New Member")
.setColor("#fff98e")
.addField(`User`, `${message.member}`)
.addField(`Joined At``${message.member.joinedAt}`)
.addField(`Total Members Now`, `${message.guild.memberCount}`)
.setFooter(`👋 🤯`);
return message.channel.send(serverembed);
});
the set log command is
client.on("message", (message) => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case "setlogchannel":
if (!message.member.hasPermission(["ADMINISTRATOR", "MANAGE_CHANNELS"]))
return message.channel.send(
"**error** You need the manage channels or administrator permission to do this!"
);
if (!message.guild.me.hasPermission(["ADMINISTRATOR", "MANAGE_CHANNELS"]))
return message.channel.send(
"**error** I don't have the correct permission to do this, Please give me the manage channel's permission"
);
serverlogchannel = message.channel.id;
const channel =
message.channel.id +
message.channel.send(`I have set this channel to the log channel!`);
break;
}
});```
message.channel.send(...)
Shouldn't it just bechannel.send(...)?
o
yep
thanks!
should not it be (ch) => ch.id ==== server.logchannel
that "id" as u are saving the ID in database
Im not using a database
;-; im dumb
then you can save the channel in the cache, not the channel ID, that way you won't have to find it every time
habit of using db everywhere xD
@hasty sparrow done it thanks mate all tho it dont look like a box now hahaha
@earnest phoenix Quick search in the d.js guild suggests stringifying the embed
@earnest phoenix @hasty sparrow Ok yea. I got it :
`var command = args[0].toLowerCase();
if(!command) return;`
aight
now time for me to get my brain fried up with shards else my bot gonna loose servers quickly ;-;
how many servers you got @earnest phoenix
then you can save the channel in the cache, not the channel ID, that way you won't have to find it every time
confused nosies how does one to that
lulw. I have 16 and i jsut want that Badge xd
i heard sharding is recommended at 2.5k
we got 1k+ 2 days ago.... gained like 700+ in a day cuz of being trending in top.gg for a day xD
but its 1k per shard strange lol
ik but few people suggested me to do it rn as my bot was getting slow
it has bunch of features tho...
alright lets go to google to search for my queries
hey
I need help
im on discord.py
when i wanna add a custom help command it wouldnt let me cos there is a standard help command, how can i cancel it out?
More likely that the code is at fault than the shard count
@earnest phoenix But. When my bot is on the botlist website. How long u think it takes to get the bot developer badge ? xd
Don't register the default help command
@earnest phoenix bot.remove_command('help')
ayy thx :))
i use client so will edit it
but ye i get the point
g'day
@earnest phoenix But. When my bot is on the botlist website. How long u think it takes to get the bot developer badge ? xd
@clever tree well, cant say... if u advertise your bot in servers, it might take a week or two else maybe a year without reaching people xD
Uff. I hope I get the 75 Servers fast. I mean my bot is not bad at all xd :P
it took almost a week to get 75+ servers WITHOUT ADVERTISING
what i did was i just hosted some events using my bot's games in my server and people invited it to their server byself xD
xd
So i know my bot could use every emoji from every Server my bot is on. But is that with animated Emojis the same ? :o
and then... for badge i applied for verification and after 4 days, they stopped verifying cuz of Memorial day so, i had to wait extra xd
So i know my bot could use every emoji from every Server my bot is on. But is that with animated Emojis the same ? :o
@clever tree yep
bots can use animated emojis without any NITRO xd
bots are having INFINITE NITRO
richer than humans 
Lul. Thats frkn nice. Then I could use soo many cooö emojis to let my Bot look cooler. Thanks xd
Is there anyway that I can code the bot so it reacts to a message and if you react to it also, it will send a message?
Yes
Ok thank you
and i am gonna pause the work of sharding in main bot now until i find a solution... if anyone finds it, please either ping me or DM me if possible ;-;
@earnest phoenix Solution to what?
@misty sigil wdym
well
i'm making 8ball for my bot
and i want the arguments to include spaces so it doesn't get cut off
javascript?
yea
if your args are in an array, you can do args.join(" "); to put all the args together, with spaces in between each element in the array
if that is what you mean
alright i am completely lost in shards now
@earnest phoenix f
How do you handle args in general with your bot?
commandhandler
https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/first-bot/command-with-arguments.md
this might help
@misty sigil what is your other question
dw got it
ok nice
now im gonna make ab!choose
if i use normal text in code, it sends that text... but embed...
can anyone show me any example to send an embed to a channel by getting a channel from shards?
solution of this
@earnest phoenix Solution to what?
@hasty sparrow
can i just make args split on ; and join the " "s
if you split args on ; you gotta join them on ;
makes sense
Do you know how to link other code
E.g if I have a website and I want when the website button is clicked something to happen in discord?
you make an api endpoint
and that button calls that endpoint
and the endpoint sends a message or makes a role, whatever
Ah okay thanks
you make an api endpoint
@earnest phoenix
You say that like it's so easy
hi guys
app.get("/whatever/the/fuck",function(req,res){if(!req.query["msg"]) return res.status(400).send("Invalid request");res.status(200).send(JSON.stringify({status:200,msg:req.query["msg"]}))})
``` @woeful pollen echo endpoint
call like this:
Is that meant to go into a .js file in the root directory??
mm yes
let app = require("express")();
app.listen(8080)
app.get("/api/echo",function(req,res){if(!req.query["msg"]) return res.status(400).send("Invalid request");res.status(200).send(JSON.stringify({status:200,msg:req.query["msg"]}))})
run that on your machine
and go to localhost:8080/api/echo?msg=hi
magik
Ok I'll test it
Ty
how do I go to localhost:8080/api/echo?msg=hi
I just typed it into the search bar
That should work
ah its a .js file
@earnest phoenix thanks
@short siren what
uh I think I got an error
I cant reach the page localhost:8080/api/echo?msg=hi
I put it into my index.js
Error: listen EADDRINUSE: address already in use :::8080
bruh
change the app.listen(8080) to app.listen(8081)
and call the page under localhost:8081/api/echo instead of localhost:8080/api/echo
whats that gonna chnage
wait @woeful pollen is the node.js process running on your pc or some hosters vps
pc
hm
can I run it from vsc
So, my question is, Is it possible to see if user A removed user B's reaction in DIscord.js
audit log
i think
Even if the auditlog in server doesn't show it?
ok then no
alright. thanks. :o
@earnest phoenix I already gave you the solution
node <yourjsfilehere>?
it can be an endpoint for everything
you can make a website out of it
you can use it as an api
how do I use it for the api
if it gets called you make something based off the parameters
Hey i used .addField(`Roles [${roles.length - 1}]`, roles.length < 10 ? roles.join(', ') : roles.length > 10 ? "\n more.." : "None") and i don't know how show first 10 roles and "more..." text :v
for example if you call /send with parameters channelid and message you send message to channelid
hey
oh okay
what is the command to add a game activity to your bot? ,_,
client.user.setActivity ig
thanks
o frick is it possible for me to host .html pages as a website?
Yes
app.get("/somesite",function(req,res){res.sendFile("C:/absolute/path/to/html/file")})
OR
app.get("/somesite",function(req,res){res.sendFile(__dirname+"/htmlfile.html")})
thanks
@hasty sparrow u mean that stringify thingy?
hello! can anyone here tell me how to get my bot's online status and/or server count just by using the discord api?
Yes
well, i saw on google and there too it was channel.send(embed)
Could build the embed in the eval
@signal radish you mean how to change the bot's status and show in howmany servers it is in inside that status?
Could build the embed in the eval
@hasty sparrow already tried it xd
i was not sitting doing nothing for 2 hours xd
nah just just actually know if the bot is online without having to go to discord
kinda like top.gg has an online indicator for the bots
u can use console.log("Bot is online") inside the ready event
i mean for outside use my idea is to put it on my smart mirror
oh
something like thids
then idk
i am not a web dev so, i don't have any idea about it...
bot.guilds.cache.size for server count
that online status
bot.guilds.cache.size for server count
@woeful pollenyes
bot.presence
i think luca just listens to presence updates
yes
ahhh
that is likely
fair enough
i thought there would be an api link that would tell your the application statusd
:/
would be easier
nah
might just make a 2nd bot and run it on the same pi as my mirror
and then the bot pings my othe rbot
🤷
for what purpose
i want to have my bot status on my smart mirror
u dont need to ping them
just add listener to PRESENCE_UPDATE event, on most libs it is presenceUpdate
yh but this way i can also use my server counter command and display the server count on my mirror 😉
if it receives a reply then it means it's online and displays the counter, else it means the bot is offline and it'll tell me it's offline
Why not send the data from the bot to wherever you need it or add a tiny web api to your bot and have that return your data?
not a bad idea either
.addField(`Roles [${roles.length - 1}]`, roles.length < 10 ? roles.join(', ') : roles.length > 10 ? "\n more.." : "None")
Shouldn't you be using roles.size?
Because roles is a collection, not an array
@plucky heart
also nesting ternary expressions is hard to read
https://oliy.is-just-a.dev/j7e2c9_4250.png lmao wym hard to read, perfectly readable english syntax sugar 
I would like to show the roles, not the number of roles
@chilly bison
?
What I'm saying is [${roles.length - 1}] wont work here
because length does not work for collections
mine 1057 @earnest phoenix 
and this is not the place for chatting so, better no vhat here xd
map them then
u will need to use map() to show all the roles
also if you just join the roles
the roles are not an array of ids, an array of objects

your code would only work if the structure looked like this
?
["role one", "role two", "role three"]
what you're probaby getting is js {119298: { name: "role", perms: {...}, id: "2222" }, 11199: { name: "role two", perms: {...}, id: "022020"} }
well, in simple words, @plucky heart you should use this code :-
const roles = member.roles.filter(r => r.id !== message.guild.id).map(r => r).join(", ") || 'none';

amd then, you can use roles to send all the roles the member has.
here, i have defined member as message.mentions.members.first()
so, be sure about this.
https://oliy.is-just-a.dev/j7e2c9_4250.png lmao wym hard to read, perfectly readable english syntax sugar
@amber fractal nightmare fuel
What is it
My code is ok but i don't know how show first 10 roles and "more" text in this - > roles.length > 10 ? "\n **more..**" @earnest phoenix
I think you need two ??
He won't show me all the roles because
embed.fields [4] .value: Must be 1024 or fewer in length.```
I want the first 10 roles to show and the text "more"
const fetch = require("node-fetch")
async function apiFetch(apikey, path) {
fetch(`https://api.hypixel.net/${path}?key=${apikey}`, {
method: "GET"
})
.then(response => response.json())
.then(data => {
return data
})
}
module.exports = class {
constructor(apikey) {
this.apikey = apikey
}
async getPlayerCount() {
let playerCount = await apiFetch(this.apikey, "playerCount")
return playerCount
}
}
For some reason, "data" returns an object with the correct number, but when I console.log playerCount it returns undefined
You need to add return to the actual fetch request.
cause that is not how async functions work
Anyone mind giving me feedback on my premium page?
I used to design bespoke online shops a few years ago so I've taken a few things from that into it
It's not live yet so I'm only going to share a screenshot of anyone wants to critique
o thanks
@turbid bough it's not advertising if I'm seeking feedback on a design in progress 🙃
hey I use a mention prefix for my bot but with commands that fetch a mentioned user it just gets my bot's mention
because message.mentions.users.first() is your bot in this case
Logik
I have tried using .last() if there is a mentioned user but then my check to see if there is a mention isn't needed
because message.mentions.users.first() is your bot in this case
@earnest phoenix no shit
alr
Is there a way to get the available voice channel bitrate limit for a guild? (d.js v12)
This is a repost since yesterday after asking the question I deadass fell asleep
Hey uhm so I am using discord.py, and when you do (prefix)help command, it shows my (almost) actual code, it shows the arguments, like this: ?kick <name> [reason=No Reason given]. How do I get rid of that? I would like it to just have an explanation. I already tried specifying help= and brief= in the command decorator. Doesnt help.
This is an example code for a command
Try settings usage to an empty string
Oh wow thank you so much
I couldnt find the solution anywhere in the docs or in forums and it was so simple in the end xD
:p
how do i make a loop cmd with erela.js
how do you compare arrays to check if theres one thing simlar between those two? discord.js javascript
how do i make a loop cmd with erela.js
@hardy vector you can use.setTrackRepeat(true)or.setQueueRepeat(true)
i figured it uy
@surreal sage sent you a friend request please we need to chat
is there something wrong with bots rn?
my bot keeps saying it leaves servers but it's not???
Outages in this servers
I'm getting a error saying I need to type a "}" and whenever I do it gives me 2 new errors. Anyone know the correct bracket thing for:
delete a '}'
})}} try this?
You did not close your opening brackets
client.on( <-- You didn't close that, that's why the error says expected ')'
On your first screenshot
Also on your seconds screenshot this ) goes last
}}}}) instead of }})}
Send me your code I'll fix it
client.on("message", (message) => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case "cat":
request('http://edgecats.net/random', function (error, response, body) {
if (!error && response.statusCode == 200) {
let serverembed = new Discord.MessageEmbed()
.setImage(body)
.setColor("#00ff00")
.setTitle("Here is your random cat")
return message.channel.send(serverembed);
break;
}}}})
client.on("message", (message) => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case "cat":
request('http://edgecats.net/random', function(error, response, body) {
if (!error && response.statusCode == 200) {
let serverembed = new Discord.MessageEmbed()
.setImage(body)
.setColor("#00ff00")
.setTitle("Here is your random cat")
return message.channel.send(serverembed);
break;
}
})
}
})```
This should be right
Better
ok so i basically reinstalled windows
and my code which used to work earlier is now giving this error in newly installed windows
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I have a command in my bot that someone can report something like a bug ETC and the bot goes and gets the message and trys to send to a channel in the support server. would this send to the support server channel or look in that guild for the id
bot.channels.get("720734167557472358").send(contact);
Depends. What do you want the warn command to do? You need to be specific and try yourself.
what would i use in eval to fetch an invite to a server, i think my bot may be abused in it. discord.js v12.2
could anyone with typescript knowledge help me work out why this is being highlighted
@sick cloud wdym highlighted
the red underline?
that lost me
that's why i said with typescript knowledge
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.reply("Vous n'avez pas les permissions pour faire cela !");
if (args[0] && !message.mentions) {
message.channel.bulkDelete(args[0]).then(() => {
message.channel
.send(`J'ai supprimé ***${args[0]} messages*** dans ce salon pour vous !`)
.then(msg => msg.delete(5000));
})
} > else if (message.mentions) {
if (!args[1]) return message.channel.send(helpembed);
message.channel.fetchMessages({
limit: 100,
}).then((messages) => {
const filterBy = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
messages = messages.filter(m => m.author.id === filterBy).array().slice(0, args[1]);
message.channel.bulkDelete(messages)
.catch(error => console.log(error.stack))
.then(() => message.channel
.send(`J'ai supprimé ***${args[1]} messages de ${filterBy.user.tag}*** dans ce salon pour vous !`)
.then(msg => msg.delete(5000)))
})
} else if (!args[0] || !message.mentions) return message.channel.send(helpembed);``` the clear user does not work  then it was executed but nothing
@sick cloud can you show the ../../config file's exports?
Well stupid question but will this work ok due to the naming scheme
https://github.com/Microsoft/vscode/issues/51343 perhaps it's this vscode issue
@magic jackal is client.resource defined?
if it isnt you'll need to client.resource = {} first
yes I just wonder if its smart to put a map inside a map or should I just add to the existing map
maybe I'll make a new one
easier that way
@sick cloud try Object.freeze on ur exported object
or using an enum
Object.freeze is probably more relevant here
uh, you're welcome?
module.exports = {
name: "guildMemberAdd",
type: "client",
run: (client, member) => {
if(member.guild.id == "710276382202134549") {
client.channels.get("710521303601250354").send(`Hello ${member}, welcome to **${member.guild.name}**!`)
}
}
}
Is there something I am missing, this just does not seem to work.
files.forEach(file => {
const props = require(`../Events/${file}`);
props.type == "client"
? client.on(props.name, (...args) => props.run(client, ...args))
: process.on(props.name, (...args) => props.run(client, ...args));
});
Do you get an error? Is the error Cannot read property 'send' of undefined?
No, I do not.
Then what happens. Did you try debugging or logging to see if the run method is actually being called.
In JS,
How can i format 100000 to -> 100,000?
you can try .toLocaleString() but it depends on your language settings
You could also use a regular expression.
like Math.round()?
nice
now do it in kotlin react 
Other than this is a python backend and react no like that
pretty amazing
do any of you know bd.js here?
what is bd
its not a language
it's a module
seems like a new
closed source lib
it's actually called "discord-script"
can't find a git repo for it
im pretty sure this is bot designer
so its basically just discord.js
its a discord.js framework with a small interpreter for "bd script" which is basically replacing placeholders with code
and that bot designer app has an option to use js or "bd script"
it uses discord.js v11 lmao
im having an issue with map functions where if the field is empty it causes a full stop on the command and doesnt send anything, is there A way Around this. Node.js
dont add an empty field
im pulling off an api, so not my choice
Forgive my ignorance but I haven't sleapt much, I was to clear a Map() then after I want to reload my commands, is this the correct way of doing it?
<Map>.clear().then(()=>{
reloadCommands(client)
})```
but if you're talking about reading fields off of a json response, then add validation, ie: check if the field exists and is of expected type before processing it
Gatcha, its the second one
@magic jackal Map.clear() is not a promise
oh yeah, in stupid
because that’s slower
You cant just clear the existing map? that seems really redundant for no reason
let me microbench this lmao
You are destructing old object and constructing a new one
instead of just altering an existing one
making a new one can cause issues because if you do that in like 30 files then its useless
it's easier to have it made once and use accompanying functions to modify it unless you really need a new one
seems like lazy coding to me idk
it’s not lazy it’s just bad practice
my issue is that my reloading command is not promise based right now which it needs to be so I can wait for the loop to finish
oh yeah
agreed
just more work for garbage collection
micro benchmarks were inconclusive
lol
both perform the same
well functionally they are identical
but in terms of readability it’s better to just not redefine if you can avoid it
it kinda suggests that your variable could be something else at any time
its another alloc
under the hood they probably both do the same, so yeah
as jacher said
creating and maintaining one class instance is more human-friendly and readable than dereferencing a variable and reassigning it a new instance lol
const myPromise = new Promise((resolve, reject) => {
if (client.commands) {
resolve('Wow I found your command map, it exists!');
}
reject(new Error('sorry, nothing was found for command map'));
});```
is this correct?
yea but it’s kinda redundant
hmm
you aren’t doing anything blocking
promises should be used when a return value isn’t guaranteed at any given time
with synchronous code like this it is
here maybe this will help
let me upload this to github nvm I'll figure it out, I'm kinda tired of coding today
check to see if its online lol
const TRAITS = body.special_abilities?.map(({ name, desc }) => `**${name}**: ${desc}`).join(" ");
so I have this, and vs code says its proper syntax, but glitch insists ive done something wrong
optional chaining probably isnt supported in glitches node version
your ?. is only in testing rn
optional chaining is node 14+ afaik
you can use the harmony flag on node 13 if glitch allows that or just use node 14

pretty sure glitch can do v12
Glitch explicitly supports the latest minor (point) release of each major LTS (even-numbered) Node.js version.
You can specify the major version on Node you'd like to use as follows:
"engines": { "node": "10.x" }
so v10 v12 and v14 once 14 becomes LTS
which should happen later this year
v12 works yeah
Is there any way to get the total server count across all shards without using the stats event from eris-sharder? Because it suddenly says that my bot has 0 servers when it said that it has 3000 before.
That would only give guilds in a shard
async function fetchMore(apikey, path, parameters) {
let para = parameters.replace(/\s/g, "%")
console.log(parameters)
return fetch(`https://api.hypixel.net/${path}?key=${apikey}${para}`, {
method: "GET"
}).then(response => response.json())
}```
"cannot read property 'replace' of undefined
its defined doe
can anyone teach me API
discord.js v11
Js is so wierd
I would recomment python :/
well , that didint help
but thanks
there's no point in using v11 and under
they're going to stop working very soon due to discord forcing intents and stateless design
use latest
i am new to discordjs
ok
i dont know if i can understand v12 or not
ok
but thanks
v12 is the same thing as v11 with a few changes
learning v12 is only difficult if you already know v11 and are too used to v11
well
or if you already have a lot of v11 code and need to convert it to v12
if you're starting, go for v12
they work the same, only the class name changed
MessageEmbed
dot
Hey guys, just a quick question... Is it okay to not use MySQL to hold guild data if the bot i'm using is meant for a restrained amount of servers ? I would continue using json this way.
const Discord = require('discord.js');
const client = new Discord.Client();
const fetch = require('node-fetch');
const { Client, DiscorsMessageEmbed } = require('discord.js');
const Prefix = "t!"
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setStatus('available')
client.user.setPresence({
game: {
name: 'Varibalites',
type: "PLAYING"
}
});
});
if (command === 'cat') {
const { file } = await fetch('https://aws.random.cat/meow').then(response => response.json());
message.channel.send(file);
}
SyntaxError: await is only valid in async function
idk why is that error
anyone help?
How could i make a leaderboard command with using a JSON file to save the level data. So fs. How could i get all data from the guild the command is asked on and how could i sort it from high to low and only for 10 members ? I knwo its very much imput. But maybe someone is able to help me :)
also ```js
if (command === 'cat') {
const { file } = await fetch('https://aws.random.cat/meow').then(response => response.json());
message.channel.send(file);
}``` is not in an event
i got this from discordjs.guide
dont just copy and paste code
You need to put that in an event with a async function to use await
and what is async?
brUh
dont judge me , i am new to js
@earnest phoenix https://anidiots.guide/other-guides/async-await
client.on('ready', async () => {
I believe that if you use await or then, it's either one or the other. Async and so await and then are meant to be used with functions that take time to resolve
hi
How could i make a leaderboard command with using a
JSONfile to save the level data. So fs. How could i get all data from the guild the command is asked on and how could i sort it from high to low and only for 10 members ? I knwo its very much imput. But maybe someone is able to help me :)
@clever tree https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
who is the person that copies code
@empty owl Thanks i will try my best ;)
you can get all the people's spot from a certain guild
wait
you can filter out people who arent part of the guild
and sort after
dont judge me , i am new to js
@earnest phoenix Also, you have to define command, and put that in a message event
good example here: https://anidiots.guide/first-bot/your-first-bot
ty
anyone know why the lines still show underneath the words when i have ```css
text-dectoration: none
trying to get rid of the
look at how you spelled it @digital ibex
pretend its spelt correctly lul
if(command === Prefix + 'meme') {
let msg = await message.channel.send("Fetching");
fetch('https://meme-api.herokuapp.com/gimme')
.then(res => res.json())
.then(json => {
let embed = new Discord.RichEmbed()
.setTitle(json.title)
.setImage(json.url)
.setFooter(`Link: ${json.postLink} | Subreddit: ${json.subreddit}`)
msg.edit(embed)
});
}
SyntaxError: await is only valid in async function
pls help
You can't use await outside an async function
didn't someone already point out the issue
how do i add a async function?
async somefunction() {
stuff
}
tysm
@earnest phoenix the Message event should be like this client.on("message", async(message) => { codes here });
u probably doesn't have "async" in the first line
ohhh , right
thanksssss

Idk if an async message listener would be a nice thing to have
Wouldn't it slow down the execution?
client.on("message", async(message) => {
if(command === Prefix + 'meme') {
let msg = await message.channel.send("Fetching");
fetch('https://meme-api.herokuapp.com/gimme')
.then(res => res.json())
.then(json => {
let embed = new Discord.RichEmbed()
.setTitle(json.title)
.setImage(json.url)
.setFooter(`Link: ${json.postLink} | Subreddit: ${json.subreddit}`)
msg.edit(embed)
});
}
@earnest phoenix is this right?
it's hid to have it to perform some actions such as createMessageCollector() createReactionCollector() etc
Because....yknow.....async doesn't allow parallel processing
where have u defined "command" @lyric mountain
Me?


THE SECOND LINE
That's a comparison
sry caps
Not a definition
sorry if i am dumb , i am new to js
Just a question
yes
Where did you get that code?
oof i meant, you would have defined command as const command = message.content....... or something like this somewhere... right?
uhhhhhhh
one sec
Did you copy it from somewhere?
if not, your code will not work cuz it doesn't know what "command" is
so, i prefer this :-
lemme write the code xd
const Discord = require('discord.js');
const client = new Discord.Client();
const fetch = require('node-fetch');
const { Client, DiscorsMessageEmbed } = require('discord.js');
const Prefix = "t!"
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setStatus('available')
client.user.setPresence({
game: {
name: 'Varibalites',
type: "PLAYING"
}
});
});
client.on("message", async(message) => {
if(command === Prefix + 'meme') {
let msg = await message.channel.send("Fetching");
fetch('https://meme-api.herokuapp.com/gimme')
.then(res => res.json())
.then(json => {
let embed = new Discord.RichEmbed()
.setTitle(json.title)
.setImage(json.url)
.setFooter(`Link: ${json.postLink} | Subreddit: ${json.subreddit}`)
msg.edit(embed)
});
}
client.login('TOKEN');
this is the full code
Did you copy it from somewhere?
no
its mine
const command = message.content.toLowerCase();
if(command === Prefix + 'meme') {
let msg = await message.channel.send("Fetching");
fetch('https://meme-api.herokuapp.com/gimme')
.then(res => res.json())
.then(json => {
let embed = new Discord.RichEmbed()
.setTitle(json.title)
.setImage(json.url)
.setFooter(`Link: ${json.postLink} | Subreddit: ${json.subreddit}`)
msg.edit(embed)
});
}```
gud for beginning coders...
jist made "command" have a value message.content.toLowerCase()
oh ok
ty
amma try it
np
tysm ✨

the moment i realised my bot is not working in this server

error SyntaxError: Unexpected end of input
just a sec
i put in the same code
of ye
at last, add });
k
amma try it
tysm ✨
np again xd
not working
same error
Mhm..
lemme go through ur code once again
client.on("message", async(message) => {
const command = message.content.toLowerCase();
if(command === Prefix + 'meme') {
let msg = await message.channel.send("Fetching");
fetch('https://meme-api.herokuapp.com/gimme')
.then(res => res.json())
.then(json => {
let embed = new Discord.RichEmbed()
.setTitle(json.title)
.setImage(json.url)
.setFooter(`Link: ${json.postLink} | Subreddit: ${json.subreddit}`)
msg.edit(embed)
});
sorry that i am disturbing u or bothering u
i am just have been trying to get it to work for 2 days
so yeah
sorry
ok u replaced } with });
lemme send ya complete code
k
const command = message.content.toLowerCase();
if(command === Prefix + 'meme') {
let msg = await message.channel.send("Fetching");
fetch('https://meme-api.herokuapp.com/gimme')
.then(res => res.json())
.then(json => {
let embed = new Discord.RichEmbed()
.setTitle(json.title)
.setImage(json.url)
.setFooter(`Link: ${json.postLink} | Subreddit: ${json.subreddit}`)
msg.edit(embed)
}
});```
amma test
now i got 2 errors 🤣
u didn't have to replce } with });
u had to add }); in new line xd
lol what errors now?
SyntaxError: missing ) after argument list
at line number? it should be written there
?
nvm
i get it...
i should have saw ur code completely again xd
so u want to code?
the*


