简体   繁体   English

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

[英]Why startWithPrefix not working in discord.js v13?

I want to update my Truth Or dare bot discord.js v12 to v13.我想将我的真心话大冒险机器人 discord.js v12 更新到 v13。 now I faced some problems when I use ping pong its works fine but when I wanna do something with my prefix it gives me this error.现在我在使用 ping pong 时遇到了一些问题,它工作正常,但是当我想用我的前缀做一些事情时,它给了我这个错误。 I've never used discord.js v13 but one of my friends says that discord.js v12 will be disappear and discord will deactivate those bots我从未使用过 discord.js v13 但我的一位朋友说 discord.js 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

Now I don't know what is the error for.现在我不知道错误是什么。 and it looks so weird to me i don't know why but v13 is like ewww.对我来说它看起来很奇怪,我不知道为什么,但 v13 就像 ewww。 is anyone can help me, please有人可以帮助我吗?

here is my Code that i was use in discord v13.这是我在 discord v13 中使用的代码。 i just changed the client line rest all are same我刚刚更改了客户线 rest 都一样

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);

The issue is not with your prefix, it is due to you sending embeds incorrectly.问题不在于您的前缀,而是由于您错误地发送了嵌入。

You are currently sending embeds for example:您当前正在发送嵌入,例如:

    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))

A correct way to send embeds would be something like:发送嵌入的正确方法如下:

    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)]
        }

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

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