Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

javascript - Discord.js | 尝试使用嵌入时使用@ing用户[关闭](Discord.js | @ing user when trying to use an embed [closed])

I am trying to make a bot with embedded messages, this is my app.js, embd.js and error.(我正在尝试制作一个嵌入消息的机器人,这是我的app.js,embed.js和错误。)

Note: Whenever I run the command I get the error, the command is supposed to be !embed, and it's supposed to return the code in the embed.js file.(注意:每当我运行命令时,都会出现错误,该命令应该被嵌入!并且应该返回embed.js文件中的代码。) Instead I get an @ and nothing else, If you wish to add me on discord my discord is GenerallyStevie#6166.(取而代之的是,我得到一个@,但没有其他提示,如果您希望将我加为不和,那么我的不和为GeneralStevie#6166。)

app.js code:(app.js代码:)

// Require discord.js package
const Discord = require("discord.js");
const embed = require("discord.js");

// Create a new client using the new keyword
const client = new Discord.Client();

const {
    token
} = require("./token.json");

// Create array for clean code
const stringArray = ["ready", "reconnecting", "disconnect", "message", "!hello", "!help", "!embed"];

// Display a message when the bot comes online
client.on(stringArray[0], () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

// reconnecting event
client.on(stringArray[1], () => {
    console.log(`This bot is reconnecting: ${client.user.tag}`);
});

// disconnect event
client.on(stringArray[2], () => {
    console.log(`This bot is now disconnected: ${client.user.tag}`);
});

// Check for new messages
client.on(stringArray[3], msg => {
    const toLower = msg.content.toLowerCase();

    // Send back a reply when the specific command has been written by a user.
    if (toLower === stringArray[4]){
        msg.reply("Hello World!");
    }

    // !help command
    else if (toLower === stringArray[5]){
        msg.reply("The hello world bot has 2 commands. !hello !help");
    }    
        if (toLower === stringArray[6]){
        msg.reply(embed);    
    }
});

// Log in the bot using your token (password)
client.login(token);

embed.js code:(embed.js代码:)

const embedFile = require("./embed.js");
const embed = require("embed.js");
const exampleEmbed = new Discord.RichEmbed()
    .setColor('#0099ff')
    .setTitle('Some title')
    .setURL('https://discord.js.org/')
    .setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
    .setDescription('Some description here')
    .setThumbnail('https://i.imgur.com/wSTFkRM.png')
    .addField('Regular field title', 'Some value here')
    .addBlankField()
    .addField('Inline field title', 'Some value here', true)
    .addField('Inline field title', 'Some value here', true)
    .addField('Inline field title', 'Some value here', true)
    .setImage('https://i.imgur.com/wSTFkRM.png')
    .setTimestamp()
    .setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');

Image of what happens: https://prnt.sc/q43ae2(发生的情况的图像: https//prnt.sc/q43ae2)

  ask by GenerallyStevie translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your app.js file, make "msg.reply(embed)" "msg.reply(embed.exampleEmbed)".(在您的app.js文件中,制作“ msg.reply(embed)”,“ msg.reply(embed.exampleEmbed)”。)

It says "@{Member}" because you used ".reply".(它说“ @ {Member}”,因为您使用了“ .reply”。) ".reply" just sends a message with "@{Member}" at the end, and there's more text after "@{Member}" it will to turn to "@{Member},".(“ .reply”仅发送一条末尾带有“ @ {Member}”的消息,并且在“ @ {Member}”之后还有更多文本,它将变为“ @ {Member}”。) The reason it doesn't say anything after that is because your're just calling the js file, no information from it.(之后它什么也没说的原因是因为您只是在调用js文件,而没有任何信息。) If you were to remove the ".reply" and change it to ".sendMessage" it would log in the console "Cannot send an empty message.".(如果要删除“ .reply”并将其更改为“ .sendMessage”,它将登录控制台“无法发送空消息”。)

Here's your code with this change:(这是您所做的更改的代码:)

// Require discord.js package
const Discord = require("discord.js");
const embed = require("discord.js");

// Create a new client using the new keyword
const client = new Discord.Client();

const {
    token
} = require("./token.json");

// Create array for clean code
const stringArray = ["ready", "reconnecting", "disconnect", "message", "!hello", "!help", "!embed"];

// Display a message when the bot comes online
client.on(stringArray[0], () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

// reconnecting event
client.on(stringArray[1], () => {
    console.log(`This bot is reconnecting: ${client.user.tag}`);
});

// disconnect event
client.on(stringArray[2], () => {
    console.log(`This bot is now disconnected: ${client.user.tag}`);
});

// Check for new messages
client.on(stringArray[3], msg => {
    const toLower = msg.content.toLowerCase();

    // Send back a reply when the specific command has been written by a user.
    if (toLower === stringArray[4]){
        msg.reply("Hello World!");
    }

    // !help command
    else if (toLower === stringArray[5]){
        msg.reply("The hello world bot has 2 commands. !hello !help");
    }    
        if (toLower === stringArray[6]){
        msg.reply(embed);    
    }
});

// Log in the bot using your token (password)
client.login(token);

I hope this helped with your problem.(希望这对您的问题有所帮助。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...