【问题标题】:Discord.js v12 code breaks when upgrading to v13升级到 v13 时 Discord.js v12 代码中断
【发布时间】:2021-12-01 01:20:31
【问题描述】:

将我的 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()

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

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

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

    还有一些变化。你可以在guide看到他们

    【讨论】:

      猜你喜欢
      • 2022-07-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多