升级到 v13 时 Discord.js v12 代码中断

MrM*_*cal 0 javascript discord discord.js

将我的 Discord.js 更新到 v13 时,出现许多错误:

//member.hasPermission is not a function
member.hasPermission("SEND_MESSAGES")

//Cannot send an empty message
channel.send(someEmbed)

//Cannot send an empty message
channel.send({embed: someEmbed})

//Warning: The 'message' event was deprecated, use 'messageCreate' instead
client.on("message", msg => {})

//Cannot send an empty message
channel.send(user)

//[CLIENT_MISSING_INTENTS] Valid intents must be provided for the client
const client = new Client()

//channel.join is not a function
await channel.join()
Run Code Online (Sandbox Code Playgroud)

这些在 v12 中不会发生,那么我该如何在 v13 中修复它们呢?

MrM*_*cal 6

Discord.js v13 有很多更改,而这些只是其中的一小部分。在更新到 v13 之前,您应该更改以下内容

//member.hasPermission("SEND_MESSAGES")
member.permissions.has("SEND_MESSAGES")

//channel.send(someEmbed) / channel.send({embed: someEmbed})
channel.send({ embeds: [someEmbed] }) //make sure it's an array!

//client.on("message", msg => {})
client.on("messageCreate", msg => {})

//channel.send(user)
channel.send(user.toString())

//const client = new Client()
const { Intents, Client } = require("discord.js")
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]}) //more intents may be provided

//await channel.join()
const { joinVoiceChannel } = require("@discordjs/voice") //requires installation
joinVoiceChannel({
  channelId: channel.id,
  guildId: guild.id,
  adapterCreator: guild.voiceAdapterCreator
})
Run Code Online (Sandbox Code Playgroud)

还有一些更多的变化。您可以在指南中看到它们