LinkedRoles
Sets up Discord's Linked Roles for your bot. Attach what with returns.
It serves linked-roles/verify and linked-roles/callback under your bot's server.url. Add the
callback's address under Redirects on your application's OAuth2 page. The plugin logs the exact address
at startup while it's missing.
It reads the client secret from DISCORD_CLIENT_SECRET.
abstract class LinkedRoles<
TRecords extends LinkedRoleRecords,
TScopes extends OAuthScope = never,
TKeep extends boolean = false
> extends PluginMember visibility
Filter class members by access level.
constructor
Constructs a new instance of the Plugin class
Plugin(
host: CoreBase,
[spec],
input: PluginSpecArgs<Opts, Fixed>
)Inherited from:Plugin
Showing members with Protected visibility and higher.
TRecords
The records from the options. Leave it out.
TRecords extends LinkedRoleRecordsTScopes
The scopes from the options. Leave it out.
TScopes extends OAuthScope = neverTKeep
The keepTokens from the options. Leave it out.
TKeep extends boolean = falsecore
The host, typed to the transport whose Plugin base this class extends.
protected core: TCoreInherited from:Plugin
dispatchMembers
Adds values that every handler can read. Each key becomes a member, like this.tag, and its
function returns the value. Gates and Notice.render read the same values on ctx.
Seedcord calls each function once per interaction, and once per event that has a handler.
attach() throws if seedcord already uses one of these keys, like reply, if another plugin on the
bot uses it, or if the bot attaches this plugin twice.
readonly dispatchMembers?: DispatchMemberFunctionspublic override readonly dispatchMembers = {
tag: (origin: DispatchOrigin) => `${origin.guildId}:${origin.userId}`
};Inherited from:Plugin
kv
This plugin's records in the bot's config.kv, stored under its attach key. Two attachments of
one plugin class each get their own records. Renaming the attach key leaves the records under
the old key behind.
logger
Logs under the plugin's class name, on the channel its attach key sets.
protected abstract readonly options: LinkedRolesOptions<TRecords, TScopes, TKeep>Empties the values that Discord has for a user. Use it for a user who shouldn't keep the roles that
depend on your records. The plugin keeps their tokens, and a later push writes
their values again.
A cleared user can open verifyUrl again, and the plugin then writes what your
values returns for them. To keep them out, you have to refuse them in values.
public async clear(
userId: SavedTokenUserId<TKeep, "clear">
): Promise<void>Throws:
A SeedcordError with the code PluginOAuthLoginNeeded when the user never connected,
or took your application off their account since.
Throws:
A SeedcordTypeError with the code PluginLinkedRolesTokensNotKept when the plugin doesn't
have keepTokens: true.
codegen()
Returns data that seedcord codegen writes into the bot's seedcord-gen.ts as a type.
Read it back with Generated<typeof YourPlugin>. Return plain data, or classes and objects
that a project file or your plugin's package exports. The class needs a static readonly id.
seedcord codegen calls this without running init(). Read only what the constructor stored
and the bot's files.
dispose()
Runs during teardown, in ShutdownPhase.Disconnect by default. seedcord skips it when init()
has thrown.
When init() outlasts its timeout, seedcord calls this once that init() resolves, outside any
shutdown phase. The process must still be alive for that call to happen.
dispose?(): Promisable<void>Inherited from:Plugin
public init(): voidThrows:
A SeedcordError when server.url or DISCORD_CLIENT_SECRET isn't set.
Throws:
A SeedcordTypeError when the records break one of Discord's limits.
Throws:
A SeedcordTypeError when keepTokens is on and the bot's kv keeps everything in memory.
onHmr()
Override to reload plugin state on an HMR update.
onHmr(_event: HmrUpdateEvent): Promisable<void>Inherited from:Plugin
prepareCommands()
Changes commands before seedcord sends them to Discord. Write your changes onto these objects,
like setting name_localizations. Each command appears once, even when it deploys to several guilds.
If it throws, the deploy stops, and so do seedcord codegen, a Workers build, seedcord commands deploy,
and seedcord commands list.
The CLI calls this without running init(). Read only what the constructor stored and the bot's files.
prepareCommands?(
commands: readonly RESTPostAPIApplicationCommandsJSONBody[]
): Promisable<void>Inherited from:Plugin
Runs your values again for a user who connected, and writes what it returns. Call it when
something a role depends on changes, like after a match in your game.
It resolves to a ConnectionResult. Its kind is 'connected' after a write. When your
values refused this user, its kind is 'refused' and it has the message.
public async push(
userId: SavedTokenUserId<TKeep, "push">
): Promise<ConnectionResult>Throws:
Whatever your values throws.
Throws:
A SeedcordError with the code PluginOAuthLoginNeeded when the user never connected,
or took your application off their account since. They have to open verifyUrl again.
Throws:
A SeedcordTypeError with the code PluginLinkedRolesValueRejected when your values
returns a value that doesn't fit its record, or a key that isn't in records.
Throws:
A SeedcordRangeError with the code PluginLinkedRolesValueRejected when platformName
or platformUsername is longer than Discord takes.
Throws:
A SeedcordTypeError with the code PluginLinkedRolesTokensNotKept when the plugin doesn't
have keepTokens: true.
Registers your records with Discord and sets the application's Linked Roles Verification URL to
verifyUrl. A later start skips those calls unless your records or server.url
changed, or the last time it made them was more than a day ago.
If the callback address isn't under Redirects on your application's OAuth2 page, it logs the address. Only you can add it there.
registerCommandFiles()
Tells seedcord dev which files your prepareCommands reads. Saving one of them in seedcord dev
shows the command refresh prompt.
registerCriticalFiles()
Registers critical file patterns that should trigger a full restart when changed in Dev HMR.
rejectOptions()
Rejects the options this plugin got.
public verifyUrl(): stringpublic static with<TRecords, TScopes, TKeep>(options: LinkedRolesOptions<TRecords, TScopes, TKeep>): new (host: CoreBase) => LinkedRoles<TRecords, TScopes, TKeep>const Ranked = LinkedRoles.with({
records: {
matches_won: {
type: RecordType.IntegerGreaterThanOrEqual,
name: 'Matches won',
description: 'or more matches won'
}
},
// `matches` is your own code, with what your game has for each Discord user
values: async ({ user }) => ({ metadata: { matches_won: await matches.wonBy(user.id) } })
});
seedcord.attach('linkedRoles', Ranked);