繁体   English   中英

“DiscordAPIError:无法发送空消息”

[英]"DiscordAPIError: Cannot send an empty message"

我正在尝试制作一个亵渎 discord 机器人。 每当我运行它时,它都很好,但是当我输入一个它应该过滤掉的词时,它会停止。 这是我在输入被屏蔽的词时遇到的错误。

DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\loser\Desktop\word filter bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\loser\Desktop\word filter bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\loser\Desktop\word filter bot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15)
at async Client.<anonymous> (C:\Users\loser\Desktop\word filter bot\index.js:33:19) {
method: 'post',
path: '/channels/954840804466257921/messages',
code: 50006,
httpStatus: 400,
requestData: {
json: {
  content: undefined,
  tts: false,
  nonce: undefined,
  embeds: undefined,
  components: undefined,
  username: undefined,
  avatar_url: undefined,
  allowed_mentions: undefined,
  flags: undefined,
  message_reference: undefined,
  attachments: undefined,
  sticker_ids: undefined
  },
  files: []
  }
  }

这是我的代码

const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const prefix = '-'

client.once('ready', () => {
console.log('woohoo, Im ready to get online and block some words!')
client.user.setActivity('-help', {type: 'LISTENING'})
})

client.on('message', async message => {
if(message.channel.type === 'dm' || message.author.bot) return;

const logChannel = client.channels.cache.find(channel => channel.id === '954845946326450206')
let words = ["banana", "orange"]

let foundInText = false;
for (var i in words) {
    if (message.content.toLowerCase().includes(words[i].toLowerCase())) foundInText = true;
}

if (foundInText) {
    let logEmbed = new Discord.MessageEmbed()
    .setDescription(`<@${message.author.id}> Said a bad word`)
    .addField('The Message', message.content)
    .setColor('RANDOM')
    .setTimestamp()
    logChannel.send(logEmbed)

    let embed = new Discord.MessageEmbed()
    .setDescription(`That word is not allowed here`)
    .setColor('RANDOM')
    .setTimestamp()
    let msg = await message.channel.send(embed);
    message.delete()
    msg.delete({timeout: '3500'})
}
})

无论如何你们可以帮助我吗? 我真的很想启动并运行它。

我假设您使用的是 discord.js v13。

从 v13 开始, send方法只接受一个参数。 您可以使用send({ embeds: [your, cool, embeds] }); 发送嵌入或任何不仅包含内容的消息。

此外, Message.prototype.delete()现在不接受任何参数。 如果您想在一定时间后删除消息,则必须使用setTimeout

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM