为什么startWithPrefix在discord.js v13中不起作用



我想更新我的Truth Or dare bot discord.js v12到v13。现在,当我使用乒乓球时,我遇到了一些问题,它工作得很好,但当我想用前缀做一些事情时,它会给我这个错误。我从未使用过discord.js v13,但我的一个朋友说,discord.jss v12将消失,discord将停用那些机器人

> node .
Truth Or Dare 2.0#2237 Has logged in
(node:107) DeprecationWarning: The message event is deprecated. Use messageCreate instead
(Use `node --trace-deprecation ...` to show where the warning was created)
/home/runner/TOD/node_modules/discord.js/src/rest/RequestHandler.js:349
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (/home/runner/TOD/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/runner/TOD/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
at async TextChannel.send (/home/runner/TOD/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:172:15) {
method: 'post',
path: '/channels/874498102139166730/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: []
}
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! TOD@1.0.0 start: `node .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the TOD@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-11-24T08_19_36_335Z-debug.log
exit status 1

现在我不知道错误是什么原因。在我看来,这太奇怪了,我不知道为什么,但v13就像ewww。有人能帮我吗,

这是我在discord v13中使用的代码。我刚换了客户线路,其余都是相同的

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

// ======== Ready Log ========
client.on ("ready", () => {

console.log(`${client.user.tag} Has logged in`)
async function ll() {
let totalMembers = 0;
for (const guild of client.guilds.cache) {
totalMembers += (await guild[1].members.fetch()).size;
}
var status = '+helme | Truth Or Dare'
const types = ['PLAYING', 'WATCHING', "STREAMING"]     
let randomType = types[Math.floor(Math.random() * types.length)]
if (randomType === 'PLAYING') status = `+helpme | @${client.user.username}` 
if (randomType === 'STREAMING') {
status = `${totalMembers} members`
}
if (randomType === 'WATCHING') {
status = `${client.guilds.cache.size} servers`
}
client.user.setPresence({activity: {type: randomType, url: "https://www.twitch.tv/", name: status}, status:  'STREAMING'});
//     client.user.setPresence({activity: {type: types[Math.floor(Math.random() * types.length)], url: "https://www.twitch.tv/", name: `${status[Math.floor(Math.random() * status.length)]}`}, status:  ss[Math.floor(Math.random() * ss.length)]});

}
setInterval(() => {
ll()
}, 5000)
}); 
// ======== Code ========
// Array of possible truth replies
const t = [
"If you could be invisible, what is the first thing you would do?", 
"What is a secret you kept from your parents?", 
"What is the most embarrassing music you listen to?", 
"What is one thing you wish you could change about yourself?",
"Who is your secret crush?"
];
// Array of possible dare replies
const d = [
"Do a free-style rap for the next minute.",
"Let another person post a status on your behalf.",
"Hand over your phone to another player who can send a single text saying anything they want to anyone they want.",
"Let the other players go through your phone for one minute.",
"Smell another player's armpit",
"Smell another player's bare foot.",
"Eat a bite of a banana peel",
"Do an impression of another player until someone can figure out who it is.",
"Take a selfie right now and send it here",
"Say I love to your Crush"
];
const tb = [
"যদি আপনি অদৃশ্য হতে পারেন, আপনি প্রথম জিনিস কি করবেন?",
"কোন সিক্রেট কথা আপনি আপনার বাবা-মায়ের কাছ থেকে গোপন রেখেছিলেন?",
"আপনার শোনা সবচেয়ে বিব্রতকর সঙ্গীত কোনটি?"
]
const db = [
"এক মিনিটের জন্য একটি ফ্রি-স্টাইল রেপ করুন।",
"সোশ্যাল মিডিয়ায় পোস্ট দিন ``আমি একজন পাগল ব্যাক্তি``",
"এখানের কাওকে এক মিনিটের জন্য ফোন করুন।",
"তোমার ক্রাশকে মেসেজ দাও ``আমি তোমাকে ভালোবাসি`` এবং ‍স্ক্রিনশট  এখানে দাও",
]
client.on('message', message => {
if(message.content === 'ping'){
message.channel.send('pong')
}
if (message.author.bot || !message.guild || !message.content.startsWith(prefix)) return;
const command = message.content.substring(prefix.length);
// Match the command
if (command === "t") { // Truth
const truth = t[Math.floor(Math.random() * t.length)];
message.channel.send(new Discord.MessageEmbed()
.setColor('#FAA81A')
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.setTitle("Truth")
.setDescription(truth))
message.react("😇");
}
else if (command === "d") { // Dare
const dare = d[Math.floor(Math.random() * d.length)];
message.channel.send(new Discord.MessageEmbed()
.setColor('#7B00F7')
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.setTitle("Dare")
.setDescription(dare))
message.react("😈");
}
else if (command === "tb") { // Truth
const truth = tb[Math.floor(Math.random() * tb.length)];
message.channel.send(new Discord.MessageEmbed()
.setColor('#FAA81A')
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.setTitle("Truth Bangla")
.setDescription(truth))
message.react("😇");
}
else if (command === "db") { // Dare
const dare = db[Math.floor(Math.random() * db.length)];
message.channel.send(new Discord.MessageEmbed()
.setColor('#7B00F7')
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.setTitle("Dare Bangla")
.setDescription(dare))
message.react("😈");
}
else if (command === "inviteme") {
const invite = new Discord.MessageEmbed()
.setColor('3a86ff')
.setTitle("Invite Me")
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.setDescription("Click on **[Invite Me]('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')** to invite this bot on your server ")
message.channel.send(invite)
message.react("🤖");
}
else if (command === "vote"){

const vote = new Discord.MessageEmbed()
.setColor('3a86ff')
.setTitle("Vote Me")
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')

.setDescription(`[discordbotlist.com](https://discordbotlist.com/bots/truth-or-dare-7260/upvote) Click on **[Vote]('https://discordbotlist.com/bots/truth-or-dare-7260/upvote')** or click the button down bellow to Vote Me`)
let button = new disbut.MessageButton()
.setStyle('url')
.setURL('https://discordbotlist.com/bots/truth-or-dare-7260/upvote') 
.setLabel('Vote Me') 
.setDisabled(); 
message.channel.send(vote)
message.react("🤖");
}
// else if (message, "post") {
//   let announcement = message.content.substring(6);
//   let announcementsChannel = client.channels.cache.get('874498102139166731');
//   if (announcementsChannel)
//     announcementsChannel.send(announcement)
// }
else if (command === "helpme") { // Help
const help = new Discord.MessageEmbed()
.setColor('#111133')
.setTitle("Truth Or Dare")
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.addFields(
{ name: 'For Help', value: '```+helpme```' },
{ name: 'For Your Truth', value: '```+t```', inline: true },
{ name: 'For Your Dare', value: '```+d```', inline: true},
{ name: 'For Invite this bot on your server', value: '```+inviteme```' },
{ name: 'For Truth Questions Bangla', value:'```+tb```', inline: true},
{ name: 'For Dare Questions Bangla', value:'```+db```', inline: true},
{ name: 'Created By', value: '<@723821826291138611> [**Leader at CODE HUNTER**]' },
)
.setDescription(
`Truth Or Dare Bot Version: v${require("./package.json").version}
[Website](https://web-truthordare.web.app/) | [Support Server](https://discord.gg/djhNPX2QUp) | By [Code Hunter](https://github.com/Code-Hunter-OfficialBD/)`
)
.setTimestamp()
.setFooter(`${message.author.username} `, message.author.displayAvatarURL());
message.channel.send(help)
message.react("✅");
}
else if (command === "post") {
const ch = message.mentions.channels.first();
ch.send(message.content.substring(prefix.length + command.length))
}

});
const token = process.env.TOKEN;
client.login(token);

问题不在于前缀,而是由于您发送的嵌入不正确。

您当前正在发送嵌入,例如:

message.channel.send(new Discord.MessageEmbed()
.setColor('#7B00F7')
.setURL('https://discord.com/api/oauth2/authorize?client_id=874488895037911041&permissions=259846043712&scope=bot')
.setTitle("Dare")
.setDescription(dare))

发送嵌入的正确方式如下:

message.channel.send(
{ embeds: [new Discord.MessageEmbed()
.setColor('#7B00F7')
.setURL('https://discord.com/api/oauth2/authorize? 
client_id=874488895037911041&permissions=259846043712&scope=bot')
.setTitle("Dare")
.setDescription(dare)]
}

最新更新