#development

1 messages · Page 981 of 1

wild mist
#

Does welcome message cant use embed?

summer torrent
#

why?

sacred oyster
#

Anyone knows a good working event handler tutorial?

quartz kindle
#

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

sacred oyster
#

Oh

#

So I can just copy and paste my command handler and change some stuff?

quartz kindle
#

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

sacred oyster
#

are there any good tutorials you know?

quartz kindle
#

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

proper mist
#
  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

pale vessel
#

It doesn't seem to work
as in what

#

did you set the correct overwrites for that role?

proper mist
#

wdym overwrites (i'm kinda new at bot dev)

tepid canyon
#

The channel permissions for the role

#

Like did you make sure the muted role has at least send messages disabled (red tick)

proper mist
#

Yes

#

It just doesn't give the user the role

pale vessel
#

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?

proper mist
#

No because i'm using glitch and idk where the console is

pale vessel
#

there should be a button on the bottom

proper mist
#
  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

tepid canyon
#

member.roles.add(role) instead work? pretty sure .id isnt needed

proper mist
#

Ok let me check

#

Nope still doesn't work

#

:/

tepid canyon
#

Is your bots role above the muted role?

proper mist
#

Yes it is

tepid canyon
#

You should open your console because it is most likely putting an error

proper mist
#

Ok I will go find the console :P lol

tepid canyon
#

Once we see the error it may be easier to assess whats happening

proper mist
#

Ok

#

Nothing is wrong with it :/

lyric acorn
#

who knows how to make a bump bot

pale vessel
#

id isn't needed but can be used

#

can you try logging the role?

earnest phoenix
lyric mountain
#

Oh my

earnest phoenix
#

Any one can help me

zenith terrace
#

@earnest phoenix try deleting the discord.js module then re add it

vale garden
#

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

solemn latch
#

when a collector ends, theres an event.
you can make your next collector, on that event

vale garden
#

no see i get that

#

but

#

wait

#

oh

#

the collecter.on("end"

#

?

solemn latch
#

yep

vale garden
#

kk

#

thx

cunning gorge
#

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

earnest phoenix
#

send is a promise

#

you're trying to delete the promise, not the message it returns

cunning gorge
#

ah ok

#

how would I fix it?

earnest phoenix
#

use async/await or Promise pattern

cunning gorge
#

ah

#

so if I just do

#

await message.delete(loading)?

#

that would work?

earnest phoenix
#

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")

cunning gorge
#

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)
earnest phoenix
#

delete() doesn't take messages as options... The only option it has is timeout

cunning gorge
#

Oh

#

Is there another thing to use besides message.delete() to achieve the same result?

earnest phoenix
#

oh yeah then just call delete on your loading variable

#

other than that

#

the code is correct

cunning gorge
#

When you mean call delete on my loading variable, isnt that what I have now? in the message.delete(loading) part

earnest phoenix
#

loading.delete()

#

your loading variable is the returned message object

cunning gorge
#

oh ok

#

gotcha

#

Thank you!

#

And they all need to have awaits right?

earnest phoenix
#

correct

cunning gorge
#

gotcha

earnest phoenix
#

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

cunning gorge
#

Ah ok

#

So usually everything should just be awaited?

earnest phoenix
#

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

cunning gorge
#

ah ok thanks guys

vale garden
#

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

solemn latch
#

if someone stands, the game is over

vale garden
#

what

solemn latch
#

blackjack hands end, when the player stands

vale garden
#

lol i need to learn blackjack properly then

#

lmao

#

wait

#

im so dumb

#

yeah

#

lol

solemn latch
#

my blackjack game is 1-5 player

#

thats where the fun is

vale garden
#

lol

earnest phoenix
#

@earnest phoenix try deleting the discord.js module then re add it
@zenith terrace now new error pepe_crf

zenith terrace
#

Which is

zenith terrace
#

@earnest phoenix remove the 12 from the node part then retype 12

#

I messed about with this before and something fixed it

earnest phoenix
#

Ok

zenith terrace
#

Yea just give it time now

#

Until it finishes

#

See if it works or not

earnest phoenix
#

But it is still spaming

zenith terrace
#

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

earnest phoenix
#

It was working well yesterday

#

I cloned that project

#

Now lets see its working or not

hardy vector
#
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.

civic idol
#

How does the Streaming work in a status?

atomic quarry
#

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?

hardy vector
#

lavalink?

atomic quarry
#

discord.js I believe

halcyon ember
#
      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
solemn latch
lost stag
#

2

ancient lichen
#

anyone that has a good arithmetic function to get levels and points? I have one but it's s**t ;P

solemn latch
#

ngl, im using the runescape formula, but its a pretty steep curve

ancient lichen
#

ikr same

unborn steeple
#

why doesnt client.ping work on v12 d.js

solemn latch
wheat valve
#

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?

vale garden
#

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

solemn latch
#

I use visual studio code
it has a feature called format code(shift + alt + f)
it formats things quite nicely imo

paper phoenix
#

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 } )
sudden geyser
#

You could also use ESLint, which is a popular linter.

vale garden
#

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"

paper phoenix
#

Not a good idea to nest listeners. It'll work, sure.

vale garden
#

ok

paper phoenix
#

But if your collector collects x items, your end function will fire x times.

vale garden
#

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

paper phoenix
#

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?

vale garden
#

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

paper phoenix
#

Will be able to help later if someone doesn't in the meantime. 😛

vale garden
#

lol ok

#

SOMEONE HELP PLZZZZ

#

lol

#

@someone

plush fractal
#

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

vale garden
#

lol thats literally what he said

#

can you see my question

#

@plush fractal

true ravine
#

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

smoky spire
#

Yes it's normal

earnest phoenix
#

guys what i have to do to make my bot online 24/7 on glitch

#

help me

true ravine
#

Cool thank you

harsh dock
#

@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 nameMas_bored

wanton nova
#

didnt they block pinging websites for a bit?

#

since they were having issues

harsh dock
#

Idk

wanton nova
#

so its very hard to keep it 24/7 on glitch at the moment

harsh dock
#

It was easy before

wanton nova
#

¯_(ツ)_/¯

#

my bot went down constantly when i used it

#

i probably did something wrong

harsh dock
#

What you did pp878

wanton nova
#

i dont remember

#

😎

harsh dock
#

Lol

#

Im waiting they approve my bot Mas_bored

wanton nova
#

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
     }
  }
harsh dock
#

@wanton nova i think you need to
Change [] to {}

wanton nova
#

thought you would get the property via [] though...

#

thats what MDN is saying

hexed storm
#

So glitch.com is currently blocking ping services, some of my bots are down because of this

wanton nova
#

but i guess i'll try

harsh dock
#

@hexed storm you can open your projects at rdp

wanton nova
#

nope still didnt delete it @harsh dock

harsh dock
#

Ok idk

wanton nova
#

oh wait

#

im an idiot

harsh dock
#

Lol why

wanton nova
#

turns out game was something else 😳

#

not the user id

harsh dock
hexed storm
#

Thank god for Heroku

wanton nova
#

yep

#

i forgot i changed the variable somewhere

#

honest mistake pogey

harsh dock
#

Lol

hexed storm
#

Or maybe repl.it? CPU speed is comparable to that of a sloth

wanton nova
#

i tried

#

wasn't a good experience

harsh dock
#

@hexed storm
Freshping
Or
Uptimerobot

#

Try them

hexed storm
#

going to try migrating one of my projects from glitch to replit

wanton nova
#

as i said repl isnt worth it

tight plinth
#

Guys, just don't use glitch

hexed storm
#

First things first, I need to modify the code to load the token from .env

wanton nova
#

@tight plinth some people have no other options pogey

hexed storm
#

replit free doesn't allow you to make your projects private

tight plinth
#

Heroku is the best free option by far

hexed storm
#

So any tokens not in .env will be shunted

tight plinth
#

Just because of uptime

harsh dock
#

@tight plinth
Heroku is not like glitch oCMz19

tight plinth
#

Yep

hexed storm
#

Heroku's the best free host in my opinion

tight plinth
#

Because glitch sucks!

#

Its not meant to host discord bots

harsh dock
#

Lol both is bad
I use visual studio code

golden condor
#

Visual studio code isn't a host

#

Lmao

harsh dock
#

Ik

wanton nova
hexed storm
#

The fact that you're getting hosting for FREE outweighs everything

golden condor
#

Yeah the free stuff means you can't complain that much

tight plinth
#

I have a vps for free sungwasses

golden condor
#

You are just lucky

tight plinth
#

Ye

midnight hazel
#

Hey

wanton nova
#

student credit moment pogey

#

after my azure credit's done, i could just move on to AWS

#

then github students

cunning gorge
#

If anyone could help me create a reaction menu for my help command with discord.js pls lmk!

harsh dock
#

@cunning gorge what reaction menu like if you press it you get role or something like that?

cunning gorge
#

well it edits an embed

#

but basically ye, does an action

harsh dock
#

Come dm i will show you my bot there is something like that

cunning gorge
#

Thank you!

harsh dock
#

If you want

cunning gorge
#

sure

pure lion
#

How do I remove something from a JSON using fs?

earnest phoenix
#
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

tight plinth
#

@earnest phoenix you copy pasted code

#

Please use your own code

earnest phoenix
#

a friend sent me this code and told me to try it

tight plinth
#

Well your friend is not a good programmer

#

Or you are not

pure lion
#

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"
 ]
}
quartz kindle
#

why do you need each guild id twice?

pale vessel
#

you can use an array and the includes() function

quartz kindle
#

there's a lot of unneeded stuff there

pure lion
#

Fuc-

sick cloud
#

err can i use .map on a Map?

pale vessel
#

no

sick cloud
#

ok cool

#

is there any other sort of thing like it

quartz kindle
#

you can use a discord collection

pale vessel
#

discord collection is really handy

quartz kindle
#

otherwise you can use a for loop to emulate the same behavior

sick cloud
#

i'm not using a discord bot

pale vessel
#

use a loop

sick cloud
#

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

quartz kindle
#

well you can npm install discordjs/collection

#

you can use Map.keys/values/entries()

pale vessel
#

a for loop isn't hard either

quartz kindle
#

and use .map on that, but it wont modify the original Map

pale vessel
#

so it's really your choice

sick cloud
#

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

quartz kindle
#

[...Map.values()].map(item => item.username)

sick cloud
#

(node:16432) UnhandledPromiseRejectionWarning: TypeError: this.activeClients.values(...).map is not a function

#

oh

#

you edited

pale vessel
#

edited

quartz kindle
#

ye, forgot map.values() returns an iterator

sick cloud
quartz kindle
#

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

sick cloud
#

sweet

#

is there a way to make date.toLocaleTimeString use 24h time

quartz kindle
#

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]

sick cloud
#

got it

#

also, is there a way to repeat a string x times

#

like ```

-.repeat(width of screen)```

quartz kindle
#

yeah exactly that lmao

#

string.repeat(n)

sick cloud
#

ah ok

#

and is there some way to work out ws latency, i don't think ws offers any latency

white anvil
#

it does

#

what lib are you using

sick cloud
#

normal ws on node

quartz kindle
#

they have a .ping() method but in their examples they just send a message and wait for a response

white anvil
#

ping also takes a callback

#

it doesn’t actually return anything

sick cloud
#

well i do custom like discord, should i just send the ping(store the date) and when its acknowledged calc the difference?

white anvil
#

yes

quartz kindle
white anvil
#

it’s probably simpler to use ping() w/ callback

quartz kindle
#

but the api also has these

sick cloud
long yew
#

can someone help?

#

i got a red thing

#

and don't know what to change

earnest phoenix
#

hi

#

error: relation "guilds_subscriptions" does not exist

#

any body help

sinful belfry
#

@long yew looks like you may be missing a couple brackets on the line above

earnest phoenix
#

help me also

hoary lily
long yew
#

@sinful belfry where do i add them?

earnest phoenix
#

@hoary lily that my problem is related to database

sinful belfry
#

just add )) at the end of the line declaring the variable

scarlet dragon
#

-bots

gilded plankBOT
long yew
#

@sinful belfry thanks so much

sinful belfry
#

-usebots @scarlet dragon

gilded plankBOT
sinful belfry
#

don't use them here please

scarlet dragon
#

@sinful belfry where i use?

#

testing 1 and testin 2 ?

sinful belfry
#

yup

scarlet dragon
#

huh

#

im sorry about this

#

i didnt know

long yew
#

i got that

sinful belfry
#

the error says it all

quartz kindle
#

you're trying to use something that doesnt exist

long yew
#

idk how to define args

sinful belfry
#

it is just defining a variable, as you usually would

long yew
#

i haven't done js for a year

sinful belfry
#

and call it args

long yew
#

and it was the older version

quartz kindle
#

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

hoary lily
#

let args = blah blah

earnest phoenix
#

pls help out

hoary lily
#

Define

earnest phoenix
#

?

hoary lily
#

Oof sorry not you bro

earnest phoenix
#

ok

hoary lily
#

I can't help with database I'm noob too

long yew
#

@hoary lily what do i make them equal?

hoary lily
#

You define the undefined args -_-

long yew
#

i use const args

#

is that wrong?

hoary lily
#

No

#

I'll show you how I defined args

vale garden
#
        //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
#

Sorry I'm noob too@long yew

#

I use "" when using the " ` ", " ' "

#

\

long yew
#

@hoary lily idk where to put that though

hoary lily
#

That's in my index file

long yew
#
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

hoary lily
#
message.channel.send("**\`The Match is a draw!\`**");
#

Define args before where it's needed

long yew
#

when i do

#

it says message is not defined

#

even though it is

hoary lily
#

Uhm I'm sorry I'm not good, I'm afraid I give you wrong solutions

quartz kindle
#

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)

long yew
#

yeah

#

i want it to be when i tag someone

quartz kindle
#

that means you're expecting the args[1] variable to contain a valid user ID

long yew
#

it shows their avatar

quartz kindle
#

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?

long yew
#

message.mentions

quartz kindle
#

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()

long yew
#
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
quartz kindle
#

depending if you want a user or a member

long yew
#

i'll check

hoary lily
#

I'm confused with user and member too

#

But I think user is used as individual and member as guild member

long yew
#

i'm doing user

pale vessel
#

a user has no association with the guild/server so no joined timestamp, roles, etc.

quartz kindle
#

user contains information about your account, such as username, profile picture, etc...

long yew
#

yeah

quartz kindle
#

member contains information about you in a specific guild, for example, roles, nicknames, etc

long yew
#

that is what i'm trying

hoary lily
#

Thanks! Good thing we have supoortive devs here.

long yew
#

so is it js const args = message.mentions.users.first()

quartz kindle
#

yes, that would define the variable args as the first mentioned user

long yew
#
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?

quartz kindle
#

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]

long yew
#
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' }))
      )
    }
  })
quartz kindle
#

members.fetch() returns a promise

#

it needs to be awaited

long yew
#

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' }))
      )
    }
  })
quartz kindle
#

and by the way, when a user is mentioned, all its data is included in the message

long yew
#

ok

quartz kindle
#

there is no need to get them or fetch them from anywhere

#

those two lines are basically redundant and unneeded

long yew
#

var person = message.guild.member(message.mentions.users.first() || await message.guild.members.fetch(args))

#

those?^

quartz kindle
#

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

long yew
#
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?

quartz kindle
#

yes

#

but you're still displaying the author's avatar

#

not the mentioned user's

long yew
#

ohh

#
.setImage(message.mentions.user.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))
#

that?

quartz kindle
#

no

#

you already defined the mentioned user as args

#

just use it

long yew
#

.setImage(message.args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))

quartz kindle
#

no

#

just args

long yew
#

.setImage(args.displayAvatarURL({ dynamic: true, size: 2048, format: 'png' }))

quartz kindle
#

yes

long yew
#

ok

hoary lily
#

Congratulations bro

long yew
#
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

quartz kindle
#

you might wanna learn/relearn some basic javascript in the future, to avoid having problems with basic things like this

long yew
#

ok

#

thanks

#

when i write .avatar @quartz kindle for e.g nothing comes up

quartz kindle
#

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))

long yew
#

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' }))
      )
    }
  })
warm marsh
#

Did you mention someone?

long yew
#

that is the thing

#

when i mention myself or no one

#

it crashes

warm marsh
#

It will give you an error when you provide no mention because your command is heavy reliant on it.

long yew
#

ok

warm marsh
#

Also, Having a new message listener for each command isn't a good idea

long yew
#

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' }))
      )
    }
  })
warm marsh
#

Yes

long yew
#

so it does the second one

warm marsh
#

You only need one client.on('message') listener

#
client.on('message', function(message) {
  if (message.content.startsWith(prefix+"command")) {

  }

  else if // another command etc
});
long yew
#

do i add all of that

#

or just the else if?

warm marsh
#

Just the else if.

long yew
#

ok

warm marsh
#

You know how it works right?

long yew
#

yeah

warm marsh
#

😐

long yew
#

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

warm marsh
#

yikes

#

Remove the second client.on

#

You only need the if statement

long yew
#

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?

warm marsh
#

No

#

Why do you have avatar twice?

long yew
#

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?

cinder patio
#

i suggest learning the basics of javascript before making a bot

warm marsh
#

^

long yew
#

i already have all kick commands and stuff

#

i just haven't done js in a year

pale vessel
long yew
#

;-;

#
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

woeful pollen
#

Well done!

long yew
#

dam

#

it has an error

#

still

woeful pollen
#

What isbit

#

Whats the error

pale vessel
#

why else if

long yew
#
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' }))
        )
      }
    });
pale vessel
#

did you mention a user

long yew
#

when i write .avatar i get that error

woeful pollen
#

You need to mention a user

#

Or do

#
if(!args) args = message.author
quartz kindle
#

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

long yew
#

oof

#

i am confusion

quartz kindle
#

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

surreal notch
#

i need help in member joined in discord.js v12

woeful pollen
#

What's your issue

surreal notch
#

idk how to set member joined date

woeful pollen
#

You can get that information from a member object

warm marsh
#
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

long yew
#

HELP

#

HELP!

#

i'm scared

#

with what happened

#

MY BOT IS SPAMMING AVATARS

#

MINE MY FRIENDS AND IT'S OWN

#

HELP

warm marsh
#

Ofc it will

#
  1. you don't check if it's a bot sending a message.
  2. you don't actually have other commands so it will always send avatar or try to.
long yew
#

i had to close command handler

warm marsh
#

Due to the else

long yew
#
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

hoary lily
#

Add cooldown

quartz kindle
#

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

weary ridge
#

Umm guys im using discord.py, and im using a host how do i use youtube_dl.exe in it?

warm marsh
#

A windows host?

weary ridge
#

Skysilk

warm marsh
#

Yeah I found the site.

quartz kindle
#

yeah but its a windows host or a linux host?

warm marsh
#

Do you have a vps or is it a limited node host?

quartz kindle
#

which operating system did you install on it?

weary ridge
#

Ubuntu 18.04

quartz kindle
#

ah

warm marsh
#

You have access to cli?

quartz kindle
#

so ubuntu is linux, it doesnt run .exe files

hoary lily
#

Is fetching deleted message probihited?

warm marsh
#

Use the youtube-dl command

quartz kindle
#

yes

#

deleted messages cannot be fetched

hoary lily
#

How bout the cache?

quartz kindle
#

if they exist in the cache, they will still be available

hoary lily
#

For example I deleted this message then it will be still available right?

weary ridge
#

yeh when i use <play url it says i need ffmpeg installed which is youtube_dl.exe

quartz kindle
#

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

long yew
#

wow i got told off bad by the owner

hoary lily
#

Thanks again! I'm going to make anti-delete.

long yew
#

of the server my bot spammed in

weary ridge
#

lol

hoary lily
#

Create your own testing center

weary ridge
#

rip

long yew
#

lol

hoary lily
#

Well I spammed my testing center.

warm marsh
#

ffmpeg is youtube_dl.exe?

quartz kindle
#

ffmpeg has nothing to do with youtube_dl, youtube_dl just happens to include it

warm marsh
#

ffmpeg should be install by default on Ubuntu unless you're on barebones. sudo apt-get install ffmpeg --yes

hoary lily
#

ffmpeg is for js as far as i know.

#

Maybe

warm marsh
#

It's for audio

#

Not JS.

hoary lily
#

Yes i know

quartz kindle
#

ffmpeg is a general purpose media transcoder

#

for all systems and languages

weary ridge
#

yeh but i had the error on my pc until i added youtube_dl.exe in the bots folder

hoary lily
#

Noted

quartz kindle
#

windows is not the same as linux

warm marsh
#

.exe won't work on linux unless using something like Wine

quartz kindle
#

ffmpeg for windows is not the same as ffmpeg for linux

warm marsh
#

But there is usually an alternative to it.

weary ridge
#

so what do i do

quartz kindle
#

you install ffmpeg on your ubuntu machine

weary ridge
#

i did pip install ffmpeg

hoary lily
quartz kindle
#

do ffmpeg -version

weary ridge
#

k

warm marsh
#

pip installs ffmpeg correctly?

weary ridge
#

wait thanks bois

quartz kindle
#

also, you probably want to pip install ffmpeg-python as pip install ffmpeg links to some weird chinese ffmpeg lib on github

weary ridge
#

its that sudo apt install ffmpeg

vital fjord
#

+rab

quartz kindle
weary ridge
#

Thanks Tim 🙂

long yew
#

HELP

#

whenever i tag someone my bot spams

#

now my friend is so annoued with me

#

cause his server got spammed

weary ridge
#

does it say this is not a command or somethink like that?

pale vessel
#

learn javascript

long yew
#

;-;

#

i know it

pale vessel
#

you do not

weary ridge
#

@quartz kindle

quartz kindle
#

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

weary ridge
#

oh it was once \ but i changed it to / since it didn't work on pc

warm marsh
#

Use something like lavalink

weary ridge
#

omg im so happy

#

eyh

#

wth

#

im using ffmpeg and playing multiple songs in fifferent servers how

quartz kindle
#

hmm?

weary ridge
#

well when i was on my pc hosting i could only play music on 1 server but now i can play on multiple servers 🙂

quartz kindle
#

isnt that the normal behavior? maybe you were doing something wrong on windows lul

weary ridge
#

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 🙂

digital ibex
#

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?

restive furnace
#

@weary ridge psst they dont use google api, they use web scrapping

weary ridge
#

oh lol

modest maple
#

The API caps you so fucking fast

surreal notch
#

how to make random no. cmd

restive furnace
#

language, library??

surreal notch
#

discord.js v12

restive furnace
#
// 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
surreal notch
#

op

#

ty

restive furnace
#

np

quartz kindle
#

what kind of error would toString() prevent there?

digital ibex
#

¯_(ツ)_/¯

restive furnace
#

¯_(ツ)_/¯

digital ibex
#

lol

surreal notch
#

@restive furnace can i get % sign there

restive furnace
#

yes

#

just do js // lets create new variable let percent = randomNum.toString() + "%"; // now you can use "percent" variable on your code

weary ridge
#

yeh ik the api caps but what if you used the yt and spotify or soundcloud then you wouldn't be capped

restive furnace
#

k

#

@surreal notch look up, if u havent

surreal notch
#

Ya

#

done

digital ibex
#

anyone got any ideas on how i can fix my issue?

restive furnace
#

any errors?

digital ibex
#

only saying it can't find the member

quartz kindle
#

you didnt return anything

digital ibex
#

oh- im literally so dumb

#

thanks again tim 😄

quartz kindle
#

also, it would probably be better to put all the different conditions inside the members.find()

digital ibex
#

oh

empty owl
#

What’s the best way to make a documentation (for my npm package) if I don’t have web hosting

quartz kindle
#

github

empty owl
#

GitHub wiki?

summer torrent
quartz kindle
empty owl
#

seems legit

quartz kindle
#

but sure you can use github wiki or github pages

summer torrent
#

or use gitbook ¯_(ツ)_/¯

empty owl
#

oh yeah

digital ibex
#

so like, ```js
// user:
guild.members.find((e) => e.nick || e.username || e.id || e.mention)

quartz kindle
#

the readme.md is what actually shows in the npm page tho

digital ibex
#

gitbook is hard to set up lol

quartz kindle
#

so its always good to have docs there, at least the basics

empty owl
#

yea thanks

long yew
#

hi

#

what is wrong with this?

quartz kindle
#

@digital ibex ye something like that

long yew
#
    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)
          }
      }
    
    })
empty owl
#

Error?

long yew
#

only when i do .avatar [person]

#

it works

#

when i do .avatar it spams

summer torrent
#

just do if(!person) return;

digital ibex
#

oki, thanks :)

long yew
#

got that error @empty owl

quartz kindle
#

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

digital ibex
#

ok uh

long yew
#

oh

empty owl
#

What he said lol

long yew
#

what should i prioritise?

#

and stuff

quartz kindle
#

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
})

digital ibex
#

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

empty owl
#

shouldn’t ignoring dms also be first priority

quartz kindle
#

depends, there are many commands that could be used in dms too

#

its user preference basically

empty owl
#

Okay

#

client.getMember isn’t a thing I think

quartz kindle
#

its a function he made

empty owl
#

Oh

quartz kindle
#

@digital ibex show current code

digital ibex
#

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

quartz kindle
#

you dont need the extra () around it

digital ibex
#

prettier adds it

quartz kindle
#

also you can do e.user.tag instead of username#discriminator

digital ibex
#

the formatter, eris doesn't have that

quartz kindle
#

ah

#

its eris

digital ibex
#

ya

quartz kindle
#

and whats the username of the member you want to find?

digital ibex
#

MBroken

quartz kindle
#

and your search is mb

digital ibex
#

yeah

quartz kindle
#

you done have a username.toLowerCase()

digital ibex
#

?

surreal notch
#

can i set a range

#

in random no.

quartz kindle
#

mb is not an exact match, so it will not pass any of those tests except for the last two tests

solemn latch
#

You can add the output by the minimum

digital ibex
quartz kindle
#

but in the last two tests, none of them checks if the lower case version of the username starts with the search string

digital ibex
#

doesn't that do that tho?

earnest phoenix
#
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

surreal notch
earnest phoenix
#

to make it work even if the bot is already on a server

digital ibex
#

um, kick and re invite it?

earnest phoenix
#

yea

#

as u can see

#

there are 2 events

quartz kindle
#

you cant reinvite a bot with code

earnest phoenix
#

Yeah I can..

#

No, you didn't get it

#

All the commands are not working

solemn latch
earnest phoenix
#

if i'm not adding the bot

#

on the server

#

again

digital ibex
#

tim, any ideas?

quartz kindle
#

ah you mean after you change prefix, the new prefix doesnt work

earnest phoenix
#
async def on_guild_join(guild):

@client.event
async def on_guild_remove(guild):
#

Here

quartz kindle
#

@digital ibex i told you already?

earnest phoenix
#

I need a new event

#

to make it work even it is already in the server

digital ibex
#

im confused

earnest phoenix
#

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.

quartz kindle
#

@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

digital ibex
#

oh

#

so e.username.toLowerCase().startsWith(search.toLowerCase()) ?

quartz kindle
#

yes

digital ibex
#

kk

slender thistle
#

@earnest phoenix does it spit out an error

digital ibex
#

oop

#

it works :)

#

thanks again :p

earnest phoenix
#

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?

devout wagon
#

this does not make sense

slender thistle
#

You have the same thing being done twice

devout wagon
#

^

#

You're saying "if this errors, do it again"

slender thistle
#

key error happens because there's no server ID in the dictionary

earnest phoenix
#

So, what should i do

slender thistle
#

Set a prefix for the server ID?

#

Hence the except branch

earnest phoenix
#

Can u give me an example?

#

Because i can't really understand explications on english

slender thistle
#

prefixes[serverid] = "MY AWESOME PREFIX"

earnest phoenix
#

so, where i should put it

#

prefixes[serverid] = "/"

#

Istead of?

slender thistle
#

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.

earnest phoenix
#

I told you, i'm kinda bad at understanding english :c

slender thistle
#

No errors => try
Errors => except

earnest phoenix
#

Okay

slender thistle
#

You're getting error

earnest phoenix
#

so except

slender thistle
#

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 "/"

earnest phoenix
#
             return '/'```
#

with enter after

slender thistle
#

Yes

earnest phoenix
#

after get_prefix right?

slender thistle
#

what

#

In the get_prefix function

earnest phoenix
#
    with open('prefixes.json', 'r') as f:
        prefixes = json.load(f)

    return prefixes [str(message.guild.id)]
   
  except:
             return '/'
#

like that

#

right?

slender thistle
#

eeeeeeeeee

earnest phoenix
#

oh

earnest phoenix
#

i forgot try

slender thistle
#

You forgot a try

#

Yes

earnest phoenix
#

oops

#

lemme see if it will work

quaint hornet
#

Have a way to make bots share videos on voice channels?

earnest phoenix
#

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

slender thistle
#

Which line is that

earnest phoenix
#

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 ?

jovial nexus
#

is there a way to put the ytdl-core on heroku?

earnest phoenix
#

Nope

jovial nexus
#

ok, so i need to find other way to have a music command?

earnest phoenix
#

Think so

#

i tried music in heroku

#

not working

jovial nexus
#

ok thx

earnest phoenix
#

so i moved on galaxygate

blazing ravine
#

who can help me

earnest phoenix
#

@slender thistle u here?

slender thistle
#

@earnest phoenix full traceback please

blazing ravine
#

pls helppp

#

@gleaming glen

earnest phoenix
#
  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

slender thistle
#

🤔

#

Send your full code

earnest phoenix
#

full code

#

@slender thistle

#

u mean all the bot?

#

or

#

only custom pref

slender thistle
#

Entire code

earnest phoenix
#
    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}')```
slender thistle
#

ef

earnest phoenix
#

ef

slender thistle
#

Did you mean def

earnest phoenix
#

it is def

#

i copied wrong

slender thistle
#

The snippet looks fine

#

What's your d.py version

summer torrent
#

@blazing ravine check whether the bot has permissions to connect

earnest phoenix
#

last version

slender thistle
#

Which "last" version exactly

earnest phoenix
#

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 &

blazing ravine
#

checked

earnest phoenix
#

how can i find faster all the &

slender thistle
#

Ctrl + F

earnest phoenix
#

ok it's only 1

#

that i put to find others

nocturne grove
#

in VSC you can search accross all files using the search button in the top left corner

earnest phoenix
#

@slender thistle

#

i will send u the entire bot

slender thistle
#

Can't you use the search function in your text editor

earnest phoenix
#

i sent you on dm

tight plinth
#

Even after disconnecting & reconnecting it won't switch to node 13

gleaming glen
#

There should be another command to fix that

#

try the help command of nvm

frosty swan
#

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 -_-

hushed jungle
#

Why do people use brackets when declaring a const?

frosty swan
#

we use the variables that are {} inside that file

hoary lily
#

Uhm is editing a message every 1 second probihited?

frosty swan
#

otherwise there is too much code

#

Uhm is editing a message every 1 second probihited?
what r u saying?

hoary lily
#

I mean I want to show animation using message editing method

frosty swan
#

what can i do?

hoary lily
#

Uhm I want to know if it is against the api

lusty quest
#

you send every time you edit the message a API call what you think?

hoary lily
#

I don't know that's why I'm asking

lusty quest
#

yes

#

its against the rules

#

if you want to animate something maybe make it as a gif

weary ridge
#

Guys I wanna make a command <meme that comes up with an reddit image is there any tutorials?

lusty quest
#

call the reddit api

#

sadly i cant help you with d.py made this only in d.js

opaque seal
#

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?

lusty quest
#

i think there is a ratelimit event

summer torrent
#

yes

lusty quest
#

@weary ridge https://www.reddit.com/r/memes.json?sort=hot this will get a meme from r/memes from hot

summer torrent
weary ridge
#

Fr that’s it

lusty quest
#

i would suggest filtering out NSFW Stuff outside of NSFW channels (the API return Json contains a is nsfw value)

#

thats a API

weary ridge
#

Oh k

lusty quest
#

you still need to work with the return json

#

but i use it for some time now

weary ridge
#

Also my bot is being hosted and for some reason it’s sending double the texts on everything

lusty quest
#

are there 2 instanced running?

#

like one on your pc and a second one on a server

weary ridge
#

No just the server

lusty quest
#

does it still send it 2x if your bot instance is offline?

weary ridge
#

I did do it twice and other crashed so I exited that is that possibly the reason?

lusty quest
#

maybe

weary ridge
#

K brb I will restart the server

solemn latch
#

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

weary ridge
#

Yeh but you can’t stop it if you have exited the SSH Console

earnest phoenix
#

you haven't hosted a minecraft server

#

that shits cursed

solemn latch
#

whatcha mean you cant stop it if you exited ssh hmmm

weary ridge
#

Boi idk

earnest phoenix
#

not sure whats going on

#

first

#

dont use dbm

viral lynx
#

ok

#

then what?

earnest phoenix
#

code it

viral lynx
#

idk how to code ;-;

earnest phoenix
#

learn python

viral lynx
#

..

#

scripting isnt for me.. there must be any way to do it...

earnest phoenix
#

learn to code

#

then you make 24/7 bots

viral lynx
#

h m

#

I just need 24/7 script, then I can publish bot

stable grail