嗨,我正在尝试制作一个赠品机器人,我在网上找到了这个脚本,但我无法让它工作,当我按照 GitHub 上的说明配置它并尝试它时,它会出现错误提示
>[Giveaway] Started.
[Giveaway] Starting a giveaway.
[Giveaway] Giveaway details:
[Giveaway] Channel: 805865272900583455
[Giveaway] Author: 361853762291105794
[Giveaway] Time: 5
[Giveaway] Item: 400k ingame monetos test test es
C:\Users\Administrator\Desktop\Botten\node_modules\discord.js\src\rest\RequestHandler.js:154
throw new DiscordAPIError(request.path, data, request.method, res.status);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\Administrator\Desktop\Botten\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async RequestHandler.push (C:\Users\Administrator\Desktop\Botten\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
method: 'post',
path: '/channels/805865272900583455/messages',
code: 50006,
httpStatus: 400
正如你所看到的控制台日志很好,我不知道如何解决这个问题,因为我已经尽力了
这是代码
const Discord = require('discord.js');
const ms = require("ms");
/**
* @param {Discord.Client} client - the discord's client
* @param {object} options - options of the package
*/
module.exports = async function(bot, options) {
class Giveaway {
constructor(bot, options = {}) {
this.botPrefix = (options && options.prefix) || '!';
this.startCmd = (options && options.startCmd) || 'giveawaystart';
this.giveawayRole = (options && options.giveawayRole) || null;
this.embedColor = (options && options.embedColor) || '#7aefe0';
this.reactEmote = (options && options.reactEmote) || `✅`
}
}
var giveawayBot = new Giveaway(bot, options);
giveawayBot.log = (msg) => {
const loggableMsg = msg.split("\n").map(function(e) {return '[Giveaway] ' + e}).join("\n")
console.log(loggableMsg)
}
async function start() {
if (typeof giveawayBot.giveawayRole !== 'string' && giveawayBot.giveawayRole !== null) throw new TypeError(`giveawayRole must be a string`);
giveawayBot.log("Started.")
bot.on("message", async message => {
if(!message.content.startsWith(giveawayBot.botPrefix)) return;
const msgArray = message.content.slice(giveawayBot.botPrefix.length).split(" ")
const command = msgArray[0]
const args = msgArray.slice(1)
switch(command) {
case giveawayBot.helpCmd:
giveawayBot.help(message);
break;
case giveawayBot.startCmd:
giveawayBot.start(message, args);
break;
default:
giveawayBot.log("Not matching command.")
break;
}
})
}
if(bot.readyTimestamp) {
start()
} else {
bot.on("ready", () => {
start()
})
}
giveawayBot.help = (message) => {
}
giveawayBot.rollIt = (randomNumber, values) => {
for (let i = 0; i < randomNumber; i++) {
if(i == randomNumber - 1) {
return values.next();
} else {
values.next()
}
}
}
giveawayBot.start = (message, args) => {
let doesHaveRole
if(giveawayBot.giveawayRole == null) {
doesHaveRole = true
} else {
doesHaveRole = message.member.roles.cache.find(r => r.id === giveawayBot.giveawayRole)
}
if(!doesHaveRole) return message.reply("you don't have the required role to do that.")
giveawayBot.log("Starting a giveaway.")
const channel = message.channel,
time = ms(args[0]),
item = args.slice(1).join(" ");
if(isNaN(time)) return message.reply("make sure to provide correct time.").then(msg => msg.delete(5000))
if(item == undefined || item == null || item.length < 1) return message.reply("you didn't specify what do you want to give away.").then(msg => msg.delete(5000))
giveawayBot.log(`Giveaway details:\n Channel: ${message.channel.id}\n Author: ${message.author.id}\n Time: ${time}\n Item: ${item}`)
const første = new Discord.MessageEmbed()
.setColor(giveawayBot.embedColor)
.setTitle(item)
.setDescription(`Ends in: ${ms(time)}`)
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setTimestamp()
.addField(`React with the ${giveawayBot.reactEmote} emote`, `to take part in this giveaway.`)
.setFooter(bot.user.username, bot.user.displayAvatarURL)
message.channel.send(første).then(async msg => {
await msg.react(giveawayBot.reactEmote)
const timeInterval = setInterval(function() {
console.log(ms(msg.embeds[0].description.slice(9)))
if(ms(msg.embeds[0].description.slice(9)) <= 5000) {
const anden = new Discord.MessageEmbed()
.setColor(giveawayBot.embedColor)
.setTitle(item)
.setDescription(`Ended.`)
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setTimestamp(msg.embeds[0].timestamp)
.setFooter(bot.user.username, bot.user.displayAvatarURL)
msg.edit(anden)
clearInterval(timeInterval)
} else {
const tredje = new Discord.MessageEmbed()
.setColor(giveawayBot.embedColor)
.setTitle(item)
.setDescription(`Ends in: ${ms(ms(msg.embeds[0].description.slice(9)) - 5000)}`)
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setTimestamp(msg.embeds[0].timestamp)
.addField(`React with the ${giveawayBot.reactEmote} emote`, `to take part in this giveaway.`)
.setFooter(bot.user.username, bot.user.displayAvatarURL)
msg.edit(tredje)
}
}, 5000)
setTimeout(function() {
msg.channel.fetchMessage(msg.id).then(mesg => {
const reactions = mesg.reactions.find(reaction => reaction.emoji.name == giveawayBot.reactEmote)
giveawayBot.log(`Reaction count: ${reactions.count}.`)
const randomNumber = Math.floor(Math.random() * (reactions.count - 1)) + 1;
let values = reactions.users.filter(user => user !== bot.user).values()
const winner = giveawayBot.rollIt(randomNumber, values).value
if(winner == undefined) return mesg.channel.send("No one reacted to the message, so no one wins.");
mesg.channel.send(`The winner of \`${item}\` is... <@${winner.id}>!`)
})
}, time)
})
}
return giveawayBot;
}
这是在我的索引文件中
const Giveaway = require("discord.js-giveaway");
const giveaway = Giveaway(bot, {})
答案 0 :(得分:0)
此处唯一可能导致该问题的 send()
是 message.channel.send(første)
我建议:
....send({embed:første})