Skip to content
Interfaceplugin-linked-rolesv0.1.0

LinkedRolesOptions

What with takes.

interface LinkedRolesOptions<
    TRecords extends LinkedRoleRecords,
    TScopes extends OAuthScope = never,
    TKeep extends boolean = false
>

TKeep

The keepTokens you pass.

TKeep extends boolean = false

keepTokens

Saves each user's tokens in your bot's kv so you can update their values later. This needs a kv driver that saves to a file or a database. Leave it out when a user's values never change after they connect.

keepTokens?: TKeep | undefined

onResult

Returns the page that a visitor gets after the callback route, for every kind of LinkedRolesResult. Without it, they get a plain page that says what happened.

onResult?: ((result: LinkedRolesResult, request: Request) => Promisable<Response>) | undefined
// sends every visitor to your own site, with how it ended in the address
onResult: (result) => Response.redirect(`https://example.com/linked?result=${result.kind}`)

records

The values that a server can set role requirements on, by key. Discord takes 5 at most.

records: TRecords & RecordProblems<TRecords>;

scopes

Scopes to request when a user connects, like 'connections' to read their GitHub account. The plugin always adds identify and role_connections.write.

scopes?: readonly TScopes[] | undefined

values()

Returns a user's value for every record. Return { refuse: 'your message' } to refuse them, like when they have to do something in your bot first. The plugin shows them the message and doesn't write anything.

values(
    connecting: ConnectingUser<TScopes>
): Promisable<RoleConnection<TRecords> | Refusal>
// counts merged pull requests for the GitHub account on the person's Discord profile.
// reading their linked accounts needs scopes: ['connections']
values: async ({ asUser }) => {
    const accounts = await asUser.connections();
    const github = accounts.find((account) => account.type === ConnectionService.GitHub && account.verified);
    if (!github) return { refuse: 'Connect your GitHub account on Discord, then try again.' };
    return { platformUsername: github.name, metadata: { merged_prs: await mergedPullRequests(github.name) } };
}