久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何將我的代碼從 v11 遷移到 Discord.js v12?

How can I migrate my code to Discord.js v12 from v11?(如何將我的代碼從 v11 遷移到 Discord.js v12?)
本文介紹了如何將我的代碼從 v11 遷移到 Discord.js v12?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我升級到 Discord.js v12,但它破壞了我現有的 v11 代碼.以下是一些導致錯誤的示例:

I upgraded to Discord.js v12, but it broke my existing v11 code. Here are some examples of things that cause errors:

// TypeError: client.users.get is not a function
const user = client.users.get('123456789012345678')

// TypeError: message.guild.roles.find is not a function
const role = message.guild.roles.find(r => r.name === 'Admin')

// TypeError: message.member.addRole is not a function
await message.member.addRole(role)

// TypeError: message.guild.createChannel is not a function
await message.guild.createChannel('welcome')

// TypeError: message.channel.fetchMessages is not a function
const messages = await message.channel.fetchMessages()

const {RichEmbed} = require('discord.js')
// TypeError: RichEmbed is not a constructor
const embed = new RichEmbed()

const connection = await message.channel.join()
// TypeError: connection.playFile is not a function
const dispatcher = connection.playFile('./music.mp3')

如何將我的代碼遷移到 Discord.js v12 并修復這些錯誤?我在哪里可以看到引入的重大更改 v12?

How can I migrate my code to Discord.js v12 and fix these errors? Where can I see the breaking changes v12 introduced?

推薦答案

以下是人們遇到的 Discord.js v12 中引入的一些最常見的重大更改.

Here are some of the most common breaking changes introduced in Discord.js v12 that people run into.

Client#usersGuild#roles 等屬性現在是 ma??nagers,而不是緩存的 Collection的項目.要訪問此集合,請使用 cache 屬性:

Properties such as Client#users and Guild#roles are now managers, instead of the cached Collection of items. To access this collection, use the cache property:

const user = client.users.cache.get('123456789012345678')
const role = message.guild.roles.cache.find(r => r.name === 'Admin')

此外,GuildMember#addRoleGuild#createChannelTextBasedChannel#fetchMessages 等方法已移至各自的管理器:

In addition, methods such as GuildMember#addRole, Guild#createChannel, and TextBasedChannel#fetchMessages have moved to the respective managers:

await message.member.roles.add(role)
await message.guild.channels.create('welcome')
const messages = await message.channel.messages.fetch()

集合

Collection類(例如 client.users.cacheguild.roles.cacheguild.channels.cache)現在只接受 functions,而不是屬性鍵和值,用于 .find.findKey:

Collection

The Collection class (e.g. client.users.cache, guild.roles.cache, guild.channels.cache) now only accepts functions, not property keys and values, for .find and .findKey:

// v11: collection.find('property', 'value')
collection.find(item => item.property === 'value')

.exists.deleteAll.filterArray.findAll 也已被刪除:

// v11: collection.exists('property', 'value')
collection.some(item => item.property === 'value')

// v11: collection.deleteAll()
Promise.all(collection.map(item => item.delete()))

// v11: collection.filterArray(fn)
collection.filter(fn).array()

// v11: collection.findAll('property', value')
collection.filter(item => item.property === 'value').array()

.tap 現在在集合上運行一個函數,而不是在集合中的每個項目上運行:

.tap now runs a function on the collection instead of every item in the collection:

// v11: collection.tap(item => console.log(item))
collection.each(item => console.log(item))

// New .tap behaviour:
collection.tap(coll => console.log(`${coll.size} items`))

RichEmbed/MessageEmbed

RichEmbed 類已被移除;使用 MessageEmbed 類,現在用于所有嵌入(而不是僅接收到的嵌入).

RichEmbed/MessageEmbed

The RichEmbed class has been removed; use the MessageEmbed class instead which is now used for all embeds (instead of just received embeds).

const {MessageEmbed} = require('discord.js')
const embed = new MessageEmbed()

addBlankField 方法也已被刪除.該方法只是簡單地添加了一個帶有零寬度空格 (u200B) 的字段作為名稱和值,因此要添加一個空白字段,請執行以下操作:

The addBlankField method has also been removed. This method simply added a field with a zero-width space (u200B) as the name and value, so to add a blank field do this:

embed.addField('u200B', 'u200B')

語音

所有 VoiceConnection/VoiceBroadcast#play*** 方法已統一在一個 play 方法:

Voice

All of the VoiceConnection/VoiceBroadcast#play*** methods have been unified under a single play method:

const dispatcher = connection.play('./music.mp3')

Client#createVoiceBroadcast 已移至 ClientVoiceManager:

const broadcast = client.voice.createVoiceBroadcast()

此外,StreamDispatcher 擴展了 Node.js 的 stream.Writable,所以使用 dispatcher.destroy() 而不是 dispatcher.end().end 事件已被移除,取而代之的是原生 finish 事件.

Additionally, StreamDispatcher extends Node.js' stream.Writable, so use dispatcher.destroy() instead of dispatcher.end(). The end event has been removed in favour of the native finish event.

User#displayAvatarURLGuild#iconURL 等屬性現在是方法:

Properties such as User#displayAvatarURL and Guild#iconURL are now methods:

const avatar = user.displayAvatarURL()
const icon = mesage.guild.iconURL()

您還可以傳遞 ImageURLOptions 自定義格式和大小等內容.

You can also pass an ImageURLOptions to customise things like format and size.

要了解有關 v12 重大更改的更多信息,請查看 the更新指南和changelog.文檔也是尋找特定方法的好資源/屬性.

To find out more about the v12 breaking changes, take a look at the updating guide and the changelog. The documentation is also a good resource for finding a particular method/property.

這篇關于如何將我的代碼從 v11 遷移到 Discord.js v12?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應)
Check if user ID exists in Discord server(檢查 Discord 服務器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創建我的第一個機器人,但總是錯誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
主站蜘蛛池模板: www.av在线| 狠狠操狠狠搞 | 美女国产| 欧美日韩久 | 日韩中文久久 | 久久噜噜噜精品国产亚洲综合 | 91亚洲国产 | 99精品欧美一区二区蜜桃免费 | 国产成人免费在线 | 日韩av一区二区在线 | 91视视频在线观看入口直接观看 | 国产精品亚洲成在人线 | 日韩高清成人 | 美美女高清毛片视频免费观看 | 亚洲欧美日韩电影 | 男女av| 91一区二区在线观看 | 欧美精品在线一区二区三区 | 天天宗合网 | 亚洲欧洲精品成人久久奇米网 | 亚洲欧美中文日韩在线v日本 | 久久亚洲欧美日韩精品专区 | 久久精品国产99国产精品 | 精品欧美一区二区三区久久久 | 国产亚洲精品久久久久动 | 成年人在线视频 | 欧美久久精品一级c片 | 日韩a| 久久久久国产精品一区二区 | 91久久 | 91免费高清视频 | 国产精品国产成人国产三级 | 国产精品久久久久久52avav | 欧美亚洲视频在线观看 | 久久久成人免费视频 | www.激情.com | 色av一区二区三区 | 91大神xh98xh系列全部 | 日本欧美在线视频 | 亚洲高清一区二区三区 | 亚洲欧美日本在线 |