@lunibee/structures
v0.4.0
Published
> Typed wrappers around Discord payloads: messages, channels, guilds, members, roles and interactions.
Readme
@lunibee/structures
Typed wrappers around Discord payloads: messages, channels, guilds, members, roles and interactions.
bun add @lunibee/structuresimport { createChannel, ThreadChannel, GuildMember } from "@lunibee/structures";
const channel = createChannel({ id: "123456789012345678", type: 11 });
if (channel instanceof ThreadChannel) console.log(channel.archived, channel.messageCount);
channel.isThread(); // true
const member = new GuildMember({
user: { id: "223456789012345678", username: "bee" },
guild_id: "323456789012345678",
roles: [],
});
console.log(member.displayName, member.displayAvatarURL());What's inside
- Messages:
Messagewithreply,edit,delete,react,pin, flag getters andcreatedTimestamp. - Channels:
ChannelplusTextChannel,NewsChannel,DMChannel,VoiceChannel,StageChannel,CategoryChannel,ThreadChannel,ForumChannel,MediaChannel.createChannel(data)picks the class fromtype;isThread(),isTextBased(),isVoiceBased(),isDMBased()narrow. - Guild entities:
Guild,GuildMember,Role,Emoji,Invite,Webhook,AutoModerationRule,GuildWelcomeScreen,GuildOnboarding,AuditLog. - Interactions:
CommandInteraction,ComponentInteraction,ModalSubmitInteraction,AutocompleteInteraction, built bycreateInteraction(). Guards includeisChatInputCommand(),isButton(),isStringSelectMenu(),isAnySelectMenu(),isModalSubmit(),isAutocomplete().interaction.optionsresolves options, includinggetFocused()for autocomplete. PermissionsBitFieldis re-exported from@lunibee/core.
Structures attached to a client (via a ResourceContext) can call Discord directly;
detached ones throw on those methods.
What's new in 0.2.1
message.member: the author as a guild member on guild messages.GuildMember.permissionsis computed from the cached roles when Discord did not send it;permissionsIn(channelId).GuildMemberactions:kick,ban,timeout,setNickname,addRole,removeRole,edit.channel.editPermissionOverwrite(id, { ViewChannel: true, SendMessages: false }).message.createComponentCollector(),message.awaitComponent(),interaction.awaitModalSubmit().showModal()takes a builder;deferReply({ ephemeral });options.getMentionableType();ComponentInteraction.messageId.
What's new in 0.2.0
Interactions: single acknowledgement guard, fetchReply(), editFollowUp(), deleteFollowUp(), user, member, expiresAt/isExpired. Channels: typed permissionOverwrites.
Docs: https://lunibee.js.org/core-concepts/caching/
