Bot上线,但嵌入不会在不和谐中发布

时间:2020-08-16 04:30:15

标签: discord.js

我是编程新手,通过观看一些教程开始制作一个不和谐的机器人。我希望漫游器将不和的DM DM给在文本通道中键入“ -buy”的用户。运行代码时,机器人会联机并运行“您的机器人名称已在线!”。但没有发送DM。我将不胜感激任何帮助。谢谢

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

const client = new Discord.Client();

const prefix = '-';

client.once('ready', () => {
    console.log('your bot name is online!');
});


client.on('message', message =>{
    if(message.author.client) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLocaleLowerCase();
    if(command === 'buy'){
        const testEmbed = new Discord.MessageEmbed()
        .setColor(0x7f03fc)
        .setTitle('test embeddy')
        .setDescription('test description woo')
        .setFooter('this is the footer')
    try {
        message.author.send(testEmbed);
    }  catch {
        message.reply('Sorry I cannot message you! Check if your DMs are public!')
    }


    }


});

client.login('');

令牌不是问题,我将其删除,因此可以在此处上传

1 个答案:

答案 0 :(得分:0)

message.author.client返回bot客户端,并且不返回布尔值。因此,您的漫游器已被阻止。如果消息作者是机器人用户,请尝试删除该代码并编写返回布尔值的message.author.bot。它将起作用。