简体   繁体   中英

Discord Bot About Command

I'm currently coding a discord bot and i wanted a about command for the bot. This is what I coded but its not working. All my current commands are in separate files from the index.js file in a command folder. Any ideas why this one isn't working?

    const Discord = require('discord.js');
module.exports = {
    name: 'about',
    description: 'talks about the bot',
    execute(message) {
            const aboutEmbed = new Discord.MessageEmbed()
                .setColor('#0099ff')
                .setAuthor('Alien Bot: About')
                .setDescription(`Alien Bot, Created By MountainTiger144, Is A Fun Little Bot Used On ${client.guilds.cache.size}Servers With Commands Like <avatar And More! Check Them Out By Doing <help hub.`)
                .setThumbnail('https://fiverr-res.cloudinary.com/images/q_auto,f_auto/gigs/125937562/original/4efdc79b0e19dabcb3f6e7bef8318f2794250933/create-a-custom-discord-bot.png', 'https://fiverr-res.cloudinary.com/images/q_auto,f_auto/gigs/125937562/original/4efdc79b0e19dabcb3f6e7bef8318f2794250933/create-a-custom-discord-bot.png')
                .addFields(
                    { name: 'Guilds', value: `${client.guilds.cache.size}`, inline: true },
                    { name: 'Version', value: `${bot_info.version}`, inline: true },
                    { name: 'Rating', value: '7/10', inline: true },
                    { name: 'Support Server', value: 'If you need help or find a bug, please click the link [here](https://discord.gg/n293gkD) to get to our support server!', inline: true })
                
                channel.send(exampleEmbed);
            }
        }

This Is what comes up when i do <about:

ReferenceError: client is not defined
    at Object.execute (C:\Users\kiera\Desktop\Discord Bot\commands\about.js:10:104)
    at Client.<anonymous> (C:\Users\kiera\Desktop\Discord Bot\index.js:79:11)
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (C:\Users\kiera\Desktop\Discord Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\kiera\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\kiera\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\Users\kiera\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
    at WebSocketShard.onMessage (C:\Users\kiera\Desktop\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\Users\kiera\Desktop\Discord Bot\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:315:20)

You need to pass client through your execute() function in your main file, if you already pass it there then just add client to your execute() function in your command files like so:

module.exports = {
    name: 'about',
    description: 'talks about the bot',
    execute(message, client) {...}

execute() doesn't know what client is, since it hasn't been passed in, or otherwise defined. Usually when I run into this problem, just add "message." before the "client", then you're using message.client.guilds.cache.size and that should work for you, since message has been passed in.

Alternatively you can pass in client from your index.js file as a parameter, then that does basically the same thing, though that may affect your other commands, since they may not use a "client" parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM