4.1.1 changelog
Published
Entries marked Breaking change a working bot; the migration guide says what to do about them. Every release of the line is in the changelog.
Patch Changes
#424
43b9454Thanks @l7aromeo! - A mock guild'smembers.fetch({ user: ids })now resolves to a collection of each of those members, found in the cache or made the waymembers.fetch(id)makes one. It resolved to an empty collection, so in a test a message command naming two or more members by ID that the guild hasn't cached refused them all as not members of the server, while one such member resolved. Mentioned members were not affected: they come from the message's mentions.#422
22daff2Thanks @l7aromeo! -createMockClient()is typed as a logged-in client,DeepMocked<Client<true>>, as the mock already behaves. Pass it straight tocreateMockInteraction,createMockChannel,createMockUserormodule.init({ ready: { client } }): each of these failed to compile without a cast, since an interaction's client isClient<true>.client.useris no longer nullable, soclient.user!.idcan beclient.user.id. Remove anyas unknown as Client<true>cast on the mock.#430
1d0c0cfThanks @l7aromeo! - Mocks frommeocord/testingnow compute what discord.js computes from them, where they returnedundefinedor a placeholder object:- Lookups: a manager's
resolve()andresolveId()read its cache, soguild.members.resolve(id)finds a member given tocreateMockGuild.guild.members.meis the bot's member, the cached one or one with @everyone. A guild's roles and channels, and the guilds of a client's messages and interactions, belong where discord.js puts them, and everything in a guild shares its client. - Ranking and permissions:
role.comparePositionTo(),channel.permissionsFor(),member.permissionsIn()and an interaction'sappPermissionscompute from the roles, the channel'spermissionOverwritesand the bot's member. Being real, they keep working afterresetAllMocks(). - Messages:
message.memberreads the guild's member cache, so a test that removes the author's member there getsnull, as discord.js gives for an author it hasn't cached. A default message now caches its author and the author's member, as Discord's message event does.message.mentions.has(user)answers from what the content mentions. - Defaults: a role is not hoisted, managed or mentionable, with no icon, tags or colours. A member's
joinedTimestampis when the mock was made, sopartialisfalse. A message has noreference,pollor stickers.avatarURL()andiconURL()arenullwithout an avatar or icon,displayAvatarURL()is Discord's default avatar, and a mock clientisReady(). - User context menus:
targetUseris the user withtargetId, the client's cached one or one made, andtargetMemberthat user's member in a server. AtargetIdgiven later picks its user, and both stay assignable.
- Lookups: a manager's
#431
b24a0bcThanks @l7aromeo! - A mock still reads some values discord.js computes as a truthy placeholder: a message'seditable,deletable,pinnable,crosspostable,bulkDeletable,hasThreadandpartial, a member'smanageable,kickable,bannableandmoderatable, a role'seditable, a channel'sviewable,manageableanddeletableand its thread and voice counterparts, andpartialon users, channels and reactions. A test that reads one now gets a warning, once per run, that 5.0 computes it as discord.js does, and how to set it on the mock, such asmessage.editable = false, to test either way. A value the test sets is read without a warning.message.threadis the thread the message's channel caches under the message's id, as discord.js reads it. Without one it is still a placeholder thread, with a warning that 5.0 givesnullthere.#429
961455dThanks @l7aromeo! - Mocks frommeocord/testingnow pass to one another, and to the testing module, without a cast:- A mock reached through a property that may be
nullkeeps its mock API, such asmessage.member?.fetch.mockResolvedValue(member)ormessage.guild?.members.fetch. - An overloaded method's mock takes what any of its overloads takes or resolves to, such as
guild.members.fetch.mockResolvedValue(member)andchannel.messages.fetch.mockResolvedValue(message), where only the list form compiled before. createMockInteractiongivenguild: null,member: nullor a DM channel builds an interaction outside a server, typed so itsguildandmembermay benull.createMockMessageis typed as discord.js emits a message, somodule.emit('messageCreate', createMockMessage())compiles.createMockChannel(ThreadChannel)is typed as a public or private thread, as discord.js types every thread, so it fits an interaction'schannel, a guild's channels and thethreadCreateevent.getResponse(interaction).calls[n].payloadis typed by the call'smethod: aftercall.method === 'reply', it is the reply's options.ResponseCallitself is unchanged, so code that builds or extends one compiles as before.
- A mock reached through a property that may be