簡體   English   中英

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

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

我想將我的真心話大冒險機器人 discord.js v12 更新到 v13。 現在我在使用 ping pong 時遇到了一些問題,它工作正常,但是當我想用我的前綴做一些事情時,它給了我這個錯誤。 我從未使用過 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

現在我不知道錯誤是什么。 對我來說它看起來很奇怪,我不知道為什么,但 v13 就像 ewww。 有人可以幫助我嗎?

這是我在 discord v13 中使用的代碼。 我剛剛更改了客戶線 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);

問題不在於您的前綴,而是由於您錯誤地發送了嵌入。

您當前正在發送嵌入,例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM