#development
1 messages · Page 981 of 1
why?
Anyone knows a good working event handler tutorial?
there's a million ways to create event handlers
but generally it would be quite similar to a command handler, if you already have one
there will be a few differences
but many things are the same, for example reading a folder for event files, storing them somewhere
then you just need to assign them as listeners
are there any good tutorials you know?
idk about tutorials, but i know how i would do it
the discordjs.guide website has a section for command handlers, but not event handlers
if (message.content === "p;mute") {
let role = message.guild.roles.cache.find(r => r.name === "Muted")
let member = message.mentions.members.first()
member.roles.add(role.id)
setTimeout(() => {
member.roles.remove(role.id)
}, 10000);
}
});
I need help with this mute command... It doesn't seem to work
It doesn't seem to work
as in what
did you set the correct overwrites for that role?
wdym overwrites (i'm kinda new at bot dev)
The channel permissions for the role
Like did you make sure the muted role has at least send messages disabled (red tick)
It just doesn't give the user the role
@proper mist this is what we need instead of "doesn't work"
have you tried logging the role?
No because i'm using glitch and idk where the console is
there should be a button on the bottom
if (message.content === "p;mute") {
let role = message.guild.roles.cache.find(r => r.name === "Muted")
let member = message.mentions.members.first()
member.roles.add(role.id)
}
});
i just set it to this
member.roles.add(role) instead work? pretty sure .id isnt needed
Is your bots role above the muted role?
Yes it is
You should open your console because it is most likely putting an error
Ok I will go find the console :P lol
Once we see the error it may be easier to assess whats happening
who knows how to make a bump bot
Please help me
Oh my
@earnest phoenix try deleting the discord.js module then re add it
hi
someone plz tell me
how do i collect a certain message after collecting another message only
i tried few stuff before but they ended up failing
when a collector ends, theres an event.
you can make your next collector, on that event
yep
I have this
const loading = message.channel.send("Loading...")
message.channel.send("Done!")
message.delete(loading)
However, this just deletes the command prompt not the loading message. I want it to delete the sent message loading after Done is sent
send is a promise
you're trying to delete the promise, not the message it returns
use async/await or Promise pattern
yes and no; your function needs to be async so you can use await and you need to await the send method, however awaiting delete is a good practice ("async all the way")
got it, ok its in an async method,
so I need to do
const loading = await message.channel.send("Loading...")
await message.channel.send("Done!")
await message.delete(loading)
delete() doesn't take messages as options... The only option it has is timeout
Oh
Is there another thing to use besides message.delete() to achieve the same result?
oh yeah then just call delete on your loading variable
other than that
the code is correct
When you mean call delete on my loading variable, isnt that what I have now? in the message.delete(loading) part
correct
gotcha
The last function as you're doing as
<message>.delete() doesn't need the await unless you're gonna do any other functions after it
it's still good practice to await it
Yea
if you're going async, go async all the way
it gets a bit more complicated when you want something to execute in parallel so you don't await something which causes it to phase out of sequential order
yeah
Yea making it all in order of await to the asynchronous function is good if you're going asynchronous way
well, promises, not every method
Yea
if you're wondering whether a method returns a promise or not you can hit up the docs
ah ok thanks guys
hi
so i made another collector to start after the first one ends
but inside the collector
is there a way to get an output based on the combination of first and second message
cuz im making a blackjack command
and rn if someone stands and then hits
he gets 2 cards at once
if someone stands, the game is over
what
blackjack hands end, when the player stands
lol
@earnest phoenix try deleting the discord.js module then re add it
@zenith terrace now new error
Which is
@earnest phoenix remove the 12 from the node part then retype 12
I messed about with this before and something fixed it
Remove discord.js again, do the removing 12 then readding, then add discord.js again.
If that doesnt fix it then you will have to make a new project with copy all commands etc over
I cant remember how I fixed mine

It was working well yesterday
I cloned that project
Now lets see its working or not
Glitch.com is again down 
const {MessageEmbed} = require('discord.js')
module.exports = {
name: 'facts',
description: 'make fatcs meme',
execute(client, message, args) {
let text = args.slice(0).join(" ")
if(!text) return;
else {
let embed = new MessageEmbed()
.setColor("RANDOM")
.setImage(`https://api.alexflipnote.dev/facts?text=${text}`)
message.channel.send(embed)
}
}
}``` when someone does _facts with more than one word it returns an error
(node:6631) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
0|npm | embed.image.url: Not a well formed URL.
How does the Streaming work in a status?
Ok, so I have a problem. My bot is starting and the status is working, along with the commands, but when I do the command "..play" with a song the bot joins the channel for a few seconds without anything playing then it sends this message
Could not join the channel: Error [VOICE_CONNECTION_TIMEOUT]: Connection not established within 15 seconds.
Can someone please tell me how to fix this?
lavalink?
discord.js I believe
message.guild.channels.cache.find(channel => channel.name === `exchange-${state.exchange}`).send('<@&713541593121947699>, <@'+message.author.id+'> wants an exchange with note: '+details)
}
run()``` it works and finds the channel the first time but if i run it again it doesnt work

2
anyone that has a good arithmetic function to get levels and points? I have one but it's s**t ;P
ngl, im using the runescape formula, but its a pretty steep curve
ikr same
why doesnt client.ping work on v12 d.js
it was changed to client.ws.ping
https://discord.js.org/#/docs/main/stable/class/WebSocketManager
How do you make a channel move to a category once they're both made? I am making a command make a channel and a category but want the channel to be in the category. I am using discord.js. Or how do you get it to check if the category was already made and to just make the channel?
hi
does anyone know a website to sort out brackets or something
i have a 300+ line command here
and i really messed up the brackets
plz help
plz help me
does anyone know a website to sort out brackets or something
i have a 300+ line command here
and i really messed up the brackets
plz help
I use visual studio code
it has a feature called format code(shift + alt + f)
it formats things quite nicely imo
How do you make a channel move to a category once they're both made? I am making a command make a channel and a category but want the channel to be in the category. I am using discord.js. Or how do you get it to check if the category was already made and to just make the channel?
@wheat valve:
const { guild } = message;
guild.channels.create( 'parent', { type: 'category' } )
.then( parent => guild.channels.create( 'child', { parent, type: 'text' } ) )
.then( child => console.log( { child: child.id, parent: parent.id } ) );
//or if you prefer await...
const parent = await guild.channels.create( 'parent', { type: 'category' } );
const child = await guild.channels.create( 'child', { parent, type: 'category' } );
console.log( { child: child.id, parent: parent.id } )
You could also use ESLint, which is a popular linter.
hi
so basically i messed up my blacjack command
and i am now restarting
can you use the
collector.on("end"
inside the collector.on("collect"
Not a good idea to nest listeners. It'll work, sure.
ok
But if your collector collects x items, your end function will fire x times.
what does that mean
my brain is fried
and i cant understand anything
i messed up 400 lines and i am restarting
plz explain more
If you had...
collector.on( 'collect', ( ) => {
collector.on( 'end', ( ) => console.log( 'ended' );
console.log( 'collected' );
} );
``` ...and collected 3 items, your console would read:
collected
collected
collected
ended
ended
ended
Are you trying to simply end the collector the second one is collected?
im trying to
no see
it looks like this for me
collector.on("collect", () => {
console.log('something')
collector.on("end", () => {
collector2.on("collect"............
})
})
im starting a different collector
const collector = message.channel.createMessageCollector(filter, { time: 15000, max: 1})
collector.on("collect", m => {
if (m.content == "hit" && m.author.id === message.author.id) {
const blackjackh = new Discord.MessageEmbed()
blackjackh.setColor("#ff00ff")
.setAuthor(`${message.author.username} VS ${message.client.user.username}`)
.addFields(
{name: `${message.author.username}'s Deck:`, value: aaa[a] + " of " + cards[card1] + ", " + ccc[c] + " of " + cards[card3] + " & " + yyy[y] + " of " + cards[card5] + "\nValue: **`" + acy + "`**"},
{name: `${message.client.user.username}'s Deck:`, value: bbb[b] + " of " + cards[card2] + " & ||" + ddd[d] + " of " + cards[card4] + "||\n Value: **`?`**", inline: true},
)
message.channel.send(blackjackh)
} else if (m.content == "stand" && m.author.id === message.author.id) {
const blackjacks = new Discord.MessageEmbed()
blackjacks.setColor("#ff00ff")
.setAuthor(`${message.author.username} VS ${message.client.user.username}`)
.addFields(
{name: `${message.author.username}'s Deck:`, value: aaa[a] + " of " + cards[card1] + " & " + ccc[c] + " of " + cards[card3] + "\nValue: **`" + ac+ "`**"},
{name: `${message.client.user.username}'s Deck:`, value: bbb[b] + " of " + cards[card2] + ", " + ddd[d] + " of " + cards[card4] + " & " + zzz[z] + " of " + cards[card6] + "\n Value: **`"+bdz+"`**", inline: true},
)
message.channel.send(blackjacks)
}
this is my actual code
im trying to start a new collector by ending the first one only is its hit and not stand
but i cant end it at hit cuz stand needs it
you know
@paper phoenix
Will be able to help later if someone doesn't in the meantime. 😛
If you had...
collector.on( 'collect', ( ) => {
collector.on( 'end', ( ) => console.log( 'ended' );
console.log( 'collected' );
} );
...and collected 3 items, your console would read:
collected
collected
collected
ended
ended
ended
Is a gradual increase in memory usage over time in Discord JS normal?
I've looked at Tim's benchmarks but they were over a short period of time
Yes it's normal
Cool thank you
@earnest phoenix
get this
https://(project_name).glitch.me
Search for host
I think there is
(Uptimerobot) go there sign up and make new monitor place there the project link and name
Idk
so its very hard to keep it 24/7 on glitch at the moment
It was easy before
¯_(ツ)_/¯
my bot went down constantly when i used it
i probably did something wrong
What you did 
anyway i have an issue with maps
if (Object.keys(games.get(message.guild.id)).length === 1) games.delete(message.guild.id)
else delete games.get(message.guild.id)[game]
for some reason, games.get(message.guild.id)[game] doesn't actually delete anything in the map...
games and game arent the same thing, and game is defined as the user's ID
this is a rough example of how the map looks like
Map {
'711758432679624755' => {
'262410813254402048': {
// info
}
}
@wanton nova i think you need to
Change [] to {}
So glitch.com is currently blocking ping services, some of my bots are down because of this
but i guess i'll try
@hexed storm you can open your projects at rdp
nope still didnt delete it @harsh dock
Ok idk
Lol why

Thank god for Heroku
Lol
going to try migrating one of my projects from glitch to replit
as i said repl isnt worth it
Guys, just don't use glitch
First things first, I need to modify the code to load the token from .env
@tight plinth some people have no other options 
replit free doesn't allow you to make your projects private
Heroku is the best free option by far
So any tokens not in .env will be shunted
Just because of uptime
@tight plinth
Heroku is not like glitch 
Yep
Heroku's the best free host in my opinion
Lol both is bad
I use visual studio code
Ik
i use epichost.com 😎
The fact that you're getting hosting for FREE outweighs everything
Yeah the free stuff means you can't complain that much
I have a vps for free 
You are just lucky
Ye
Hey
student credit moment 
after my azure credit's done, i could just move on to AWS
then github students
i'd be swimming in credit
If anyone could help me create a reaction menu for my help command with discord.js pls lmk!
@cunning gorge what reaction menu like if you press it you get role or something like that?
Come dm i will show you my bot there is something like that
Thank you!
If you want
sure
How do I remove something from a JSON using fs?
client.on("message", message => {
if (message.content === `${prefix}afk`) {
module.exports.run = async (bot, message, args) => {
let reason = args.join(' ') ? args.join(' ') : 'I am currently afk, I will reply as soon possible.';
let afklist = bot.afk.get(message.author.id);
if (!afklist) {
let construct = {
id: message.author.id,
reason: reason
};
bot.afk.set(message.author.id, construct);
return message.reply(`you have been set to afk for reason: ${reason}`).then(msg => msg.delete(5000));
}
}
}
});```
when i do <afk
it doesnt do anything
a friend sent me this code and told me to try it
Basically I wanna check the guild ID against a value in a JSON but it's not working, any ideas?
let disabled = require('./blacklists/blacklist.json')
let gld = `${msg.guild.id}`;
var glds = disabled[gld];
if (JSON.stringify(glds[0]).toString() === gld) {
return;
}
{
"710964023117479966": [
"710964023117479966"
],
"640000564461043732": [
"640000564461043732"
]
}
why do you need each guild id twice?
you can use an array and the includes() function
there's a lot of unneeded stuff there
Fuc-
err can i use .map on a Map?
no
you can use a discord collection
discord collection is really handy
otherwise you can use a for loop to emulate the same behavior
i'm not using a discord bot
use a loop
and i'm not adding discord.js just for collections
errrr
i just need to pick usernames out of a map quickly and a for loop seems too multi line for something so small
well you can npm install discordjs/collection
you can use Map.keys/values/entries()
a for loop isn't hard either
and use .map on that, but it wont modify the original Map
so it's really your choice
well i have a map, and each has an object (auth) which inside has username and i just want to get out an array of those usernames
so dunno what'd be best
[...Map.values()].map(item => item.username)
(node:16432) UnhandledPromiseRejectionWarning: TypeError: this.activeClients.values(...).map is not a function
oh
you edited
ye, forgot map.values() returns an iterator
lots of bugs but that worked, ty
i found out you can also use Array.from(map, entry => entry[1].username) or Array.from(map, ([key,val]) => val.username)
seems more efficient
nope
toLocale functions will always use the same regional settings as your OS
the only way to change them would be to change your region settings system wide
you'll need to extract the time from other methods
such as .toTimeString().split(" ")[0]
got it
also, is there a way to repeat a string x times
like ```
-.repeat(width of screen)```
ah ok
and is there some way to work out ws latency, i don't think ws offers any latency
normal ws on node
they have a .ping() method but in their examples they just send a message and wait for a response
well i do custom like discord, should i just send the ping(store the date) and when its acknowledged calc the difference?
yes
this is what they show as an example
it’s probably simpler to use ping() w/ callback
turns out localhosting = good ping
@long yew looks like you may be missing a couple brackets on the line above
help me also
@sinful belfry where do i add them?
@hoary lily that my problem is related to database
just add )) at the end of the line declaring the variable
-bots
@sinful belfry thanks so much
-usebots @scarlet dragon
@scarlet dragon
Bots can only be used in #commands and #265156322012561408.
don't use them here please
yup
the error says it all
you're trying to use something that doesnt exist
idk how to define args
it is just defining a variable, as you usually would
i haven't done js for a year
and call it args
and it was the older version
this is not dependent on any version, its just basic javascript
you need to declare the variable, assign it whatever content it needs to have, then use it
ie: let myvariable = somethingHere then you can use myvariable in your code
let args = blah blah
Define
?
Oof sorry not you bro
ok
I can't help with database I'm noob too
@hoary lily what do i make them equal?
You define the undefined args -_-
//Hit and Stand
} else if (n.content == "stand" && n.author.id === message.author.id) {
const blackjacks = new Discord.MessageEmbed()
blackjacks.setColor("#ff00ff")
.setAuthor(`${message.author.username} VS ${message.client.user.username}`)
.addFields(
{name: `${message.author.username}'s Deck:`, value: aaa[a] + " of " + cards[card1] + ", " + ccc[c] + " of " + cards[card3] + " & " + yyy[y] + " of " + cards[card5] + "\nValue: **`" + acy + "`**"},
{name: `${message.client.user.username}'s Deck:`, value: bbb[b] + " of " + cards[card2] + ", " + ddd[d] + " of " + cards[card4] +" & " + zzz[z] + " of " + cards[card6] + "\n Value: **`"+bdz+"`**", inline: true},
)
message.channel.send(blackjacks)
collector.on("end", collected => {
if (ac > bdz && ac <= 21){
message.channel.send("**`"+message.author.username+" Wins!`**")
}
else if (bdz > ac && bdz <= 21){
message.channel.send("**`"+message.client.user.username+" Wins!`**")
}
else if (ac !== bdz && ac > 21){
message.channel.send("**`Busted! "+message.author.username+" Loses!`**")
}
else if (ac !== bdz && bdz > 21){
message.channel.send("**`Busted! "+message.client.user.username+" Loses!`**")
}
else if (ac === bdz){
message.channel.send("**`The match is a Draw!`**")
}
})
}
this is a part of my code
does anyone know why the end on messages arent getting sent
@hoary lily idk where to put that though
That's in my index file
client.on('message', message => {
var person = message.guild.member(message.mentions.users.first() || message.guild.members.fetch(args[1]))
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
my index file is one
i don't have handlers
message.channel.send("**\`The Match is a draw!\`**");
Define args before where it's needed
Uhm I'm sorry I'm not good, I'm afraid I give you wrong solutions
dude, go one step at a time, dont try guessing
you're doing mesage.guild.members.fetch(args[1]) which means you want to fetch a member using the value of args[1] right?
(which btw, fetching returns a promise, so it needs to be awaited)
that means you're expecting the args[1] variable to contain a valid user ID
it shows their avatar
so you need to define args in a way that will contain a user ID
now where do you get the user ID from? you can get it from message.content or from message.mentions
which one do you want to use?
message.mentions
so define a variable that holds the mentioned user
message.mentions contains members and users properties, which both return collections
collections have a .first() function which returns the first item found
so if you want to find the first mention in a message, you can do message.mentions.users.first() or message.mentions.members.first()
client.on('message', message => {
var person = message.guild.member(message.mentions.users.first() || message.guild.members.fetch(args[1]))
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
``` This is my code so far
depending if you want a user or a member
i'll check
I'm confused with user and member too
But I think user is used as individual and member as guild member
i'm doing user
a user has no association with the guild/server so no joined timestamp, roles, etc.
user contains information about your account, such as username, profile picture, etc...
yeah
member contains information about you in a specific guild, for example, roles, nicknames, etc
that is what i'm trying
Thanks! Good thing we have supoortive devs here.
so is it js const args = message.mentions.users.first()
yes, that would define the variable args as the first mentioned user
client.on('message', message => {
const args = message.mentions.users.first()
var person = message.guild.member(message.mentions.users.first() || message.guild.members.fetch(args[1]))
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
this good?
no
args[1] means get the second item from an array defined as args
your args is not an array, its a user object
there is no need for [1]
client.on('message', message => {
const args = message.mentions.users.first()
var person = message.guild.member(message.mentions.users.first() || message.guild.members.fetch(args))
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
ok
client.on('message', message => {
const args = message.mentions.users.first()
var person = message.guild.member(message.mentions.users.first() || await message.guild.members.fetch(args))
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
and by the way, when a user is mentioned, all its data is included in the message
ok
there is no need to get them or fetch them from anywhere
those two lines are basically redundant and unneeded
var person = message.guild.member(message.mentions.users.first() || await message.guild.members.fetch(args))
those?^
yes
you can simply directly use message.mentions.members.first()
ie: you get the member directly, instead of mentions.users and then use the user to get the member
or just use mentions.users and dont get a member
you dont need the member at all
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
this?
ohh
.setImage(message.mentions.user.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
that?
.setImage(message.args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
yes
ok
Congratulations bro
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
yay
you might wanna learn/relearn some basic javascript in the future, to avoid having problems with basic things like this
change message.content === to message.content.startsWith()
since you're adding a mention, the message will never be exactly the command
it will always be the command plus a mention
so the message needs to start with the command, not be exactly the command
if(message.content.startsWith(whatever it needs to start with))
i got that
for this
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
Did you mention someone?
It will give you an error when you provide no mention because your command is heavy reliant on it.
ok
Also, Having a new message listener for each command isn't a good idea
i have a question
can i add an else if?
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
client.setMaxListeners(20)
client.on('message', message => {
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
Yes
so it does the second one
You only need one client.on('message') listener
client.on('message', function(message) {
if (message.content.startsWith(prefix+"command")) {
}
else if // another command etc
});
Just the else if.
ok
You know how it works right?
yeah
😐
well
kinda
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
} else if client.on('message', message => {
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
})
that good
or needs some work?
@warm marsh
ok
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
} else if ('message', message => {
if (message.content === `${prefix}avatar`) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
})
that good?
um
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
} else if message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
})
@warm marsh this one good?
i suggest learning the basics of javascript before making a bot
^
lul
;-;
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
} else if {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
})
})
i've done
it
on my own
Well done!
why else if
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first()
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
} else {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
});
did you mention a user
when i write .avatar i get that error
that doesnt look like not doing js for a year, that looks like never having learned js in the first place, sorry to say lol
you're struggling with some extremely basic things, basically trying to guess stuff without understanding what or why
if you have to rely on guessing to make something work, you're gonna have a hard time on everything you want to do
i need help in member joined in discord.js v12
What's your issue
idk how to set member joined date
You can get that information from a member object
if (!args) args = message.author;
Wouldn't work due to it being a constant value.
const args = message.mentions.users.first() || message.author;
let
Having the || does roughly same thing as if !args
HELP
HELP!
i'm scared
with what happened
MY BOT IS SPAMMING AVATARS
MINE MY FRIENDS AND IT'S OWN
HELP
Ofc it will
- you don't check if it's a bot sending a message.
- you don't actually have other commands so it will always send avatar or try to.
i had to close command handler
Due to the else
client.setMaxListeners(20)
client.on('message', message => {
const args = message.mentions.users.first() || message.author;
if (message.content.startsWith(`${prefix}avatar`)) {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
} else {
message.channel.send(new Discord.MessageEmbed()
.setColor(`RANDOM`)
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
)
}
});
it was that
Add cooldown
you basically did ```js
if(message starts with avatar) send avatar
else send avatar
so everytime a message does NOT start with avatar, it will send an avatar
ANY message
Umm guys im using discord.py, and im using a host how do i use youtube_dl.exe in it?
A windows host?
Skysilk
Yeah I found the site.
yeah but its a windows host or a linux host?
Do you have a vps or is it a limited node host?
which operating system did you install on it?
Ubuntu 18.04
ah
You have access to cli?
so ubuntu is linux, it doesnt run .exe files
Is fetching deleted message probihited?
Use the youtube-dl command
How bout the cache?
if they exist in the cache, they will still be available
For example I deleted this message then it will be still available right?
yeh when i use <play url it says i need ffmpeg installed which is youtube_dl.exe
if you're listening to a messageDelete event, the event will give you the cached copy of it (if it has one), before deleting it from the cache as well
wow i got told off bad by the owner
Thanks again! I'm going to make anti-delete.
of the server my bot spammed in
lol
Create your own testing center
rip
lol
Well I spammed my testing center.
ffmpeg is youtube_dl.exe?
ffmpeg has nothing to do with youtube_dl, youtube_dl just happens to include it
ffmpeg should be install by default on Ubuntu unless you're on barebones. sudo apt-get install ffmpeg --yes
Yes i know
yeh but i had the error on my pc until i added youtube_dl.exe in the bots folder
Noted
windows is not the same as linux
.exe won't work on linux unless using something like Wine
ffmpeg for windows is not the same as ffmpeg for linux
But there is usually an alternative to it.
so what do i do
you install ffmpeg on your ubuntu machine
i did pip install ffmpeg
do ffmpeg -version
k
pip installs ffmpeg correctly?
wait thanks bois
also, you probably want to pip install ffmpeg-python as pip install ffmpeg links to some weird chinese ffmpeg lib on github
its that sudo apt install ffmpeg
+rab
Thanks Tim 🙂
HELP
whenever i tag someone my bot spams
now my friend is so annoued with me
cause his server got spammed
does it say this is not a command or somethink like that?
learn javascript
you do not
idk how your code looks like, also i dont do python, but from the error above looks like trying to use windows paths instead
/Queue\song1.mp3
backslash is windows only
oh it was once \ but i changed it to / since it didn't work on pc
Use something like lavalink
omg im so happy
eyh
wth
im using ffmpeg and playing multiple songs in fifferent servers how
hmm?
well when i was on my pc hosting i could only play music on 1 server but now i can play on multiple servers 🙂
isnt that the normal behavior? maybe you were doing something wrong on windows lul
lol
atleast im happy 🙂
now need to learn how to make e.g. pls meme , coz reddit is to hard for me its confusing
ik why it can't find Queue
coz everytime a song finishes it deletes the Queue folder and song
@warm marsh Quality on lavalink is good but its also buggy and i have less control
i wanna find a way to use google api instead
ok so it took 5 seconds for groovy to play music and my bot took 7 seconds not bad 🙂
hi, i have this: js getMember(guild, search) { guild.members.find((e) => e.id === search) || guild.members.find((e) => e.mention === search) || guild.members.find((e) => e.nick === search) || guild.members.find((e) => `${e.username}#${e.discriminator}` === search) || guild.members.find((e) => e.username === search) || guild.members.find((e) => e.username === search.toLowerCase()) || guild.members.find((e) => e.nick === search.toLowerCase()) || guild.members.find((e) => e.username === search.toLowerCase()) || guild.members.find((e) => e.username.startsWith(search.toLowerCase())) || guild.members.find((e) => e.nick && e.nick.toLowerCase().startsWith(search.toLowerCase())); }
when i do client.getMember(msg.channel.guild, args.join(' ') it says it can't find the member, any ideas why that is?
@weary ridge psst they dont use google api, they use web scrapping
oh lol
The API caps you so fucking fast
how to make random no. cmd
language, library??
discord.js v12
// this is basic js, and dont depend on library
let randomNum = Math.floor(Math.random() * 5 /* maxium number, now it is 5 */);
// now we are logging it into console to see if its working:
console.log(randomNum.toString()); // toString() to prevent unexpected errors``` @surreal notch
np
what kind of error would toString() prevent there?
¯_(ツ)_/¯
¯_(ツ)_/¯
lol
yes
just do js // lets create new variable let percent = randomNum.toString() + "%"; // now you can use "percent" variable on your code
yeh ik the api caps but what if you used the yt and spotify or soundcloud then you wouldn't be capped
anyone got any ideas on how i can fix my issue?
any errors?
only saying it can't find the member
you didnt return anything
also, it would probably be better to put all the different conditions inside the members.find()
oh
What’s the best way to make a documentation (for my npm package) if I don’t have web hosting
github
GitHub wiki?
seems legit
but sure you can use github wiki or github pages
or use gitbook ¯_(ツ)_/¯
oh yeah
so like, ```js
// user:
guild.members.find((e) => e.nick || e.username || e.id || e.mention)
gitbook is hard to set up lol
so its always good to have docs there, at least the basics
yea thanks
@digital ibex ye something like that
client.on('message', async message =>{
let args = message.content.substring(prefix.length).split(" ");
let _command = message.content.toLowerCase()
if (!_command.startsWith(prefix)) return;
var person = message.guild.member(message.mentions.users.first() || message.guild.members.fetch(args[1]));
let avatarTag = new Discord.MessageEmbed()
.setTitle('Avatar')
.setImage(person.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
let avatarUser = new Discord.MessageEmbed()
.setTitle('Avatar')
.setImage(message.author.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
switch(args[0]) {
case 'avatar':
if (message.content.includes(person)){
message.channel.send(avatarTag)
} else {
message.channel.send(avatarUser)
}
}
})
Error?
just do if(!person) return;
oki, thanks :)
you need to reorganize your code
the priorities there are wrong
first you need to check which command was used, only then you do whatever the command does
you're doing command stuff before checking if the command is actually valid
ok uh
oh
What he said lol
ignoring bots and prefix checking should be the first priority
then the command checking should be second
ie ```js
...on("message", message => {
if(message.author.bot) return
if(!message.content.startsWith(prefix)) return
// how check the command here
// then do the command's code
})
i do client.getMember(msg.channel.guild.id, args.join(' '); and it says it can't find the member, all i done was add return
shouldn’t ignoring dms also be first priority
depends, there are many commands that could be used in dms too
its user preference basically
its a function he made
Oh
@digital ibex show current code
kk
getMember(guild, search) {
console.log(search);
return (
guild.members.find((e) => e.id === search) ||
guild.members.find((e) => e.mention === search) ||
guild.members.find((e) => e.nick === search) ||
guild.members.find((e) => `${e.username}#${e.discriminator}` === search) ||
guild.members.find((e) => e.username === search) ||
guild.members.find((e) => e.username === search.toLowerCase()) ||
guild.members.find((e) => e.nick === search.toLowerCase()) ||
guild.members.find((e) => e.username === search.toLowerCase()) ||
guild.members.find((e) => e.username.startsWith(search.toLowerCase())) ||
guild.members.find((e) => e.nick && e.nick.toLowerCase().startsWith(search.toLowerCase()))
);
}```
it logs mb btw
thats meant to happen also
you dont need the extra () around it
prettier adds it
also you can do e.user.tag instead of username#discriminator
the formatter, eris doesn't have that
ya
and whats the username of the member you want to find?
MBroken
and your search is mb
yeah
you done have a username.toLowerCase()
?
mb is not an exact match, so it will not pass any of those tests except for the last two tests
You can add the output by the minimum
but in the last two tests, none of them checks if the lower case version of the username starts with the search string
doesn't that do that tho?
def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes [str(message.guild.id)]
client = commands.Bot(command_prefix = get_prefix)
@client.remove_command('help')
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = '/'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command()
@commands.has_permissions(administrator=True)
async def prefix(ctx, prefixes):
with open('prefixes.json', 'r') as f:
prefix = json.load(f)
prefix[str(ctx.guild.id)] = prefixes
with open('prefixes.json', 'w') as f:
json.dump(prefix, f, indent=4)
await ctx.send(f'I changed the prefix to: {prefixes}')
The command works, but i need to kick and reinvite the bot, what should i do
to make it work even if the bot is already on a server
um, kick and re invite it?
you cant reinvite a bot with code
@surreal notch #development message
tim, any ideas?
ah you mean after you change prefix, the new prefix doesnt work
async def on_guild_join(guild):
@client.event
async def on_guild_remove(guild):
Here
@digital ibex i told you already?
im confused
ok dm me
to test in support server
and i will show you
@earnest phoenix
Ok so
If I'm not reinviteing the bot on the server, the command won't work.
@digital ibex
username = MBroken
search = mb
e.username.startsWith(search.toLowerCase()) -> MBroken does not start with mb
e.nick && e.nick.toLowerCase().startsWith(search.toLowerCase()) -> if there is no nickname, e.nick is undefined/null
yes
kk
@earnest phoenix does it spit out an error
key error
@slender thistle
with open(....) as ...:
prefixes = json.load(...)
try:
# this will error if the guildid is not in the json
return prefixes[str(message.guild.id)]
except:
# this code will run if the stuff in the if errors
# here you need to add the guildid with your default prefix to the json
# the code is pretty similar to what you have in your on_guild_join event, youll just need to change some stuff, like how to get the current guild
# when you did that then do what you had in the try like this:
# it shouldnt error now cause the guildid is now in the json
return prefixes[str(message.guild.id)]```
Should i do it like that?
this does not make sense
You have the same thing being done twice
key error happens because there's no server ID in the dictionary
So, what should i do
Can u give me an example?
Because i can't really understand explications on english
prefixes[serverid] = "MY AWESOME PREFIX"
Well let's think for a moment here.
If the try branch runs fully without error, that means there was no error.
If there was an error during processing stuff in try branch, the except branch will run.
I told you, i'm kinda bad at understanding english :c
No errors => try
Errors => except
Okay
You're getting error
so except
Yes, but tbh, just return "/"
Until you properly rewrite the prefix system to cache instead of opening/closing files constantly, I suggest just returning the default prefix with return "/"
Yes
after get_prefix right?
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes [str(message.guild.id)]
except:
return '/'
like that
right?
eeeeeeeeee
oh
https://aws1.discourse-cdn.com/business6/uploads/glitch/original/2X/c/c331c8dda998cafc6c624faf43cdb7f44c826fef.png
https://aws1.discourse-cdn.com/business6/uploads/glitch/original/2X/f/f5df3e4ab9bb651d313c4f69c442d3a85ff407d2.png
https://aws1.discourse-cdn.com/business6/uploads/glitch/original/2X/8/836b8a4bc892e63fea96c89d2a97e22ab213b0ff.png need help thanks
i forgot try
Have a way to make bots share videos on voice channels?
Don't think so
@slender thistle
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
try:
return prefixes [str(message.guild.id)]
except:
return "/"```
Good?
I mean, like that?
SyntaxError: invalid syntax
Im getting that
Which line is that
1 sec
>>> & C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
File "<stdin>", line 1
& C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
^
SyntaxError: invalid syntax```
module.exports = async (bot, message) => {
if(message.channel.type === "dm") return;
if (!message.guild) return;
let newPrefix = db.get(`Prefix_${message.guild.id}`) || prefix
if (message.author.bot) return;
if (!message.content.startsWith(newPrefix)) return;
if (!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(newPrefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if (cmd.length === 0) return;
let command = bot.commands.get(cmd);
if (!command) command = bot.commands.get(bot.aliases.get(cmd));
if (command) command.run(bot, message, args);
if(message.mentions.bot) {
const p = new Discord.MessageEmbed()
.setColor("#ff9900")
.setDescription(`The prefix for this guild is \`${await db.get(`Prefix_${message.guild.id}`) ? await db.get(`Prefix_${message.guild.id}`) : "lt!"}\``);
message.channel.send(p);
}
}
(node:2301) UnhandledPromiseRejectionWarning: TypeError: command.run is not a function
help ?
is there a way to put the ytdl-core on heroku?
Nope
ok, so i need to find other way to have a music command?
ok thx
so i moved on galaxygate
@slender thistle u here?
@earnest phoenix full traceback please
File "<stdin>", line 1
& C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
^
SyntaxError: invalid syntax
>>> & C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
File "<stdin>", line 1
& C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
^
SyntaxError: invalid syntax
>>> & C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
File "<stdin>", line 1
& C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
^
SyntaxError: invalid syntax```
here @slender thistle
Entire code
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
try:
return prefixes [str(message.guild.id)]
except:
return '/'
client = commands.Bot(command_prefix = get_prefix)
@client.remove_command('help')
@client.event
async def on_guild_join(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(guild.id)] = '/'
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.event
async def on_guild_remove(guild):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes.pop(str(guild.id))
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
@client.command()
@commands.has_permissions(administrator=True)
async def prefix(ctx, prefixes):
with open('prefixes.json', 'r') as f:
prefix = json.load(f)
prefix[str(ctx.guild.id)] = prefixes
with open('prefixes.json', 'w') as f:
json.dump(prefix, f, indent=4)
await ctx.send(f'I changed the prefix to: {prefixes}')```
ef
ef
Did you mean def
@blazing ravine check whether the bot has permissions to connect
last version
Which "last" version exactly
where i can see
& C:/Users/Lenovo/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/Lenovo/Desktop/rareh/rareh.py
^
SyntaxError: invalid syntax
@slender thistle
it tells me about an &
checked
how can i find faster all the &
Ctrl + F
in VSC you can search accross all files using the search button in the top left corner
Can't you use the search function in your text editor
i sent you on dm
Why this don't work?
Even after disconnecting & reconnecting it won't switch to node 13
const { Router } = require("express");
const { getUser } = require("@utils/discordApi");
const btoa = require('btoa');
const fetch = require('node-fetch');
const { CLIENT_ID, CLIENT_SECRET, DOMAIN } = process.env;
const route = Router();
route.get("/", async (req, res, next) => {
if (!req.query.code) throw new Error('NoCodeProvided');
const code = req.query.code;
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`);
const response = await fetch(`https://discordapp.com/api/v6/oauth2/token?grant_type=authorization_code&code=${code}&scope=identify&redirect_uri=https://boats-list.glitch.me/api/callback`, {
method: 'POST',
headers: {
Authorization: `Basic ${creds}`,
},
});
const json = await response.json();
const [{ username, discriminator, avatar, id }, tk] = await getUser(json.refresh_token);
if (!id) return res.redirect('/login');
res.cookie("refresh_token", tk, {httpOnly: true})
res.cookie("theme", "light");
res.cookie("avatar", avatar);
res.cookie("userid", id);
res.cookie("username", username);
res.cookie("discriminator", discriminator);
res.redirect(`/`);
});
module.exports = route;
I've been doing it for 2 weeks, it continues to come out and I'm bored -_-
Why do people use brackets when declaring a const?
we use the variables that are {} inside that file
Uhm is editing a message every 1 second probihited?
otherwise there is too much code
Uhm is editing a message every 1 second probihited?
what r u saying?
I mean I want to show animation using message editing method
what can i do?
Uhm I want to know if it is against the api
you send every time you edit the message a API call what you think?
I don't know that's why I'm asking
Guys I wanna make a command <meme that comes up with an reddit image is there any tutorials?
Is there a way to make my bot throw an error when exceding a certain rate limit, for example the one of modifing the channel name more than 2 times every 10 minutes?
i think there is a ratelimit event
yes
@weary ridge https://www.reddit.com/r/memes.json?sort=hot this will get a meme from r/memes from hot
Fr that’s it
i would suggest filtering out NSFW Stuff outside of NSFW channels (the API return Json contains a is nsfw value)
thats a API
Oh k
Also my bot is being hosted and for some reason it’s sending double the texts on everything
No just the server
does it still send it 2x if your bot instance is offline?
I did do it twice and other crashed so I exited that is that possibly the reason?
maybe
K brb I will restart the server
More of a philosophy, than a rule.
But often theres no need to restart a server.
Servers often host several things, and restarting the server every time you have an issue like this is kinda silly(your shutting down anything else that's running aswell)
Its worthwhile getting into the habit of solving the issue, even if you host nothing else on it, so that if you ever do host something else on it, you're in the habit that causes the least disruption.
In this case, it was as simple as stopping the rouge bot process
Yeh but you can’t stop it if you have exited the SSH Console
whatcha mean you cant stop it if you exited ssh 
Boi idk
unexpected EOF while parsing (<fstring>, line 1)
not sure whats going on
first
dont use dbm
code it
idk how to code ;-;
learn python
why does this get an error?


