最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Code for Discord.js bot responds with error "TypeError:" - Stack Overflow

programmeradmin2浏览0评论

I'm testing sending embed messages for a Discord Bot using Discord.js which is basically a node.js module used to interact with Discord's API. This is the code i'm using for the bot to send the embed message:

const Discord = require('discord.js');
const embed = new Discord.RichEmbed()
    .setTitle("This is your title, it can hold 256 characters")
    .setAuthor("Author Name", ".png")
    .setColor(0x00AE86)
    .setDescription("This is the main body of text, it can hold 2048 characters.")
    .setFooter("This is the footer text, it can hold 2048 characters", ".png")
    .setImage(".png")
    .setThumbnail(".png")
    .setTimestamp()
    .setURL("")
    .addField("This is a field title, it can hold 256 characters",
        "This is a field value, it can hold 1024 characters.")
    .addField("Inline Field", "They can also be inline.", true)
    .addBlankField(true)
    .addField("Inline Field 3", "You can have a maximum of 25 fields.", true);

  message.channel.send({embed});

When I run the code I get this error in the Visual Studio Code IDE:

TypeError: (intermediate value).setTitle(...).setAuthor(...).setColor(...).setDescription(...).setFooter(...).setImage(...).setThumbnail(...).setTimestamp(...).setURL(...).addField(...).addField(...).addBlankField is not a function

I'm testing sending embed messages for a Discord Bot using Discord.js which is basically a node.js module used to interact with Discord's API. This is the code i'm using for the bot to send the embed message:

const Discord = require('discord.js');
const embed = new Discord.RichEmbed()
    .setTitle("This is your title, it can hold 256 characters")
    .setAuthor("Author Name", "https://i.imgur./lm8s41J.png")
    .setColor(0x00AE86)
    .setDescription("This is the main body of text, it can hold 2048 characters.")
    .setFooter("This is the footer text, it can hold 2048 characters", "http://i.imgur./w1vhFSR.png")
    .setImage("http://i.imgur./yVpymuV.png")
    .setThumbnail("http://i.imgur./p2qNFag.png")
    .setTimestamp()
    .setURL("https://discord.js/#/docs/main/indev/class/RichEmbed")
    .addField("This is a field title, it can hold 256 characters",
        "This is a field value, it can hold 1024 characters.")
    .addField("Inline Field", "They can also be inline.", true)
    .addBlankField(true)
    .addField("Inline Field 3", "You can have a maximum of 25 fields.", true);

  message.channel.send({embed});

When I run the code I get this error in the Visual Studio Code IDE:

TypeError: (intermediate value).setTitle(...).setAuthor(...).setColor(...).setDescription(...).setFooter(...).setImage(...).setThumbnail(...).setTimestamp(...).setURL(...).addField(...).addField(...).addBlankField is not a function

Share Improve this question edited Mar 12, 2020 at 8:02 DerStarkeBaer 6698 silver badges29 bronze badges asked Mar 11, 2020 at 22:34 John DoeJohn Doe 1076 silver badges12 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

There is not addBlankField() function in MessageEmbed class when you look at documentation, check your discord.js version.

As of v12.0.0 they changed RichEmbed to MessageEmbed.

Try this :

    const Discord = require('discord.js');
    const client = new Discord.Client();
    client.login('Your bot\'s token here');
    client.on('ready', () => console.log('I\'m ready !');
    client.on('message', message => {
        const embed = new Discord.MessageEmbed()
            .setTitle("This is your title, it can hold 256 characters")
            .setAuthor("Author Name", "https://i.imgur./lm8s41J.png")
            .setColor('WHITE')
            .setDescription("This is the main body of text, it can hold 2048 characters.")
            .setFooter("This is the footer text, it can hold 2048 characters", "http://i.imgur./w1vhFSR.png")
            .setImage("http://i.imgur./yVpymuV.png")
            .setThumbnail("http://i.imgur./p2qNFag.png")
            .setTimestamp()
            .setURL("https://discord.js/#/docs/main/indev/class/RichEmbed")
            .addField("This is a field title, it can hold 256 characters",
        "This is a field value, it can hold 1024 characters.")
            .addField("Inline Field", "They can also be inline.", true)
            .addField("Inline Field 3", "You can have a maximum of 25 fields.", true);

  message.channel.send(embed);

If that doesn't work, I would suggest checking the official documentation clicking here

If you want to add a blank field in another way, because .addBlankField() isn't supported in discord.js v12. You can write this:

.addField("** **", "** **")

This will add a field with an almost empty title and description (They both contain one space after you sent the embed)

.addField('\u200B', '\u200B');

发布评论

评论列表(0)

  1. 暂无评论