【问题标题】:Trying to embed hyperlinks for a discord bot with javascript尝试使用 javascript 为不和谐的机器人嵌入超链接
【发布时间】:2020-12-17 09:55:45
【问题描述】:

我想创建一个不和谐的机器人,当有人键入 -ping 时,它会给出一个嵌入的超链接。

我的当前代码是:

“嵌入.js”

const Discord = require('discord.js');


const client = new Discord.Client();


const prefix = '-';
 
const fs = require('fs');
 
client.commands = new Discord.Collection();
 
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);
 
    client.commands.set(command.name, command);
}
 
 
client.once('ready', () => {
    console.log('embed is online!');
});
 
client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;
 
    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
 
    if(command == 'ping'){
        Discord.MessageEmbed.channel.send(exampleEmbed)
    } 
});
 
client.login('NzQ4ODQ3MzYwMjA5MzIxOTg0.X0jYcw.fZjcPUwrpEQPkQyqQdxprCYVH6g');

“ping.js”

 const Discord = require('discord.js');
 
 
 const exampleEmbed = new Discord.MessageEmbed();

    exampleEmbed.setTitle('Some title');
    exampleEmbed.setURL('https://discord.js.org/');


Discord.Message.channel.send(exampleEmbed);

我正在尝试遵循这个:

https://discordjs.guide/popular-topics/embeds.html#embed-preview 有了这个指南, https://www.youtube.com/watch?v=AUOb9_aAk7U&list=PLbbLC0BLaGjpyzN1rg-gK4dUqbn8eJQq4&index=3

欢迎任何帮助或反思,但请像 5 岁或橡皮鸭一样解释。

【问题讨论】:

    标签: javascript discord bots


    【解决方案1】:

    您的嵌入代码似乎正确,但您需要使用Discord.Message.channel.send({ embed: exampleEmbed });发送它

    此外,我建议您重新生成您的机器人令牌here,因为它允许任何人控制您的机器人。

    【讨论】:

    • ty 和对令牌的良好调用。它应该可以工作,但每次我尝试命令 C:\Users\philip von wowern\Desktop\Discord\embed.js:32 Discord.Message.channel.send({ embed: exampleEmbed }); 时都会收到此错误消息^ 类型错误:无法读取客户端未定义的属性“发送”。
    猜你喜欢
    • 1970-01-01
    • 2022-01-19
    • 2021-09-26
    • 2018-03-20
    • 2020-12-25
    • 2022-06-12
    • 2021-01-21
    • 2017-10-08
    • 1970-01-01
    相关资源
    最近更新 更多