Warm tip: This article is reproduced from serverfault.com, please click

why do my basic commands output, but my embed command doesn't?

发布于 2020-11-30 13:43:45

I'm quite new to js, and i have been following a tutorial until now. I wanted to break away and create a command that would make an embedded message in discord (as an output). I have tried a few different ways, but none of the solutions seem to be working. When i run the command ?embed , nothing shows up, here is the if statement;

if(command === 'swept'){
       client.commands.get("swept").execute(message, args);
    } else if(command == 'youtube'){
        client.commands.get("youtube").execute(message, args);
    } else if (command == 'embed'){
        client.commands.get("embed").execute(message, args);
    }
})

The other two commands (?swept, ?youtube) work fine. Here is the piece of code that the command calls to for the embed;

const Discord = require('discord.js')
module.exports = {
    name: 'embed',
    description: "embed test if im not stupid",
    execute(message, args) {
        const embed =  new Discord.MessageEmbed()
            .setTitle('Title')
            .addField('Field1', 'Field2')
            .addField('field 3', 'FiElD4')
            .setColor('#0aaaf5')
            message.channel.send(embed);
    }
}

A solution or even an easier way to do it would be appreciated. The other two commands are coded the same way (in a separate file starting with module.exports = ...)

EDIT: Error message;

   const embed =  Discord.messageEmbeded()
                               ^

TypeError: Discord.messageEmbeded is not a function
    at Object.execute (C:\Users\alexh\Desktop\discord botting\commands\embed.js:8:32)
    at Client.<anonymous> (C:\Users\alexh\Desktop\discord botting\main.js:33:38)     
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (C:\Users\alexh\Desktop\discord botting\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\alexh\Desktop\discord botting\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\alexh\Desktop\discord botting\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (C:\Users\alexh\Desktop\discord botting\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\alexh\Desktop\discord botting\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\Users\alexh\Desktop\discord botting\node_modules\ws\lib\event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)
Questioner
animecabbage
Viewed
0
Florian Kamps 2020-12-01 00:15:36

You've not imported Discord.js lib in your file. Try to import it at the top of your file:

const Discord = require('discord.js')

Then, the function for a discord embed is not .messageEmbeded but .messageEmbed.

Replace your line 8 by this:

const embed = new Discord.messageEmbed()