Acting in a server
Beyond answering runs and presses, your wisp can act on its own:
var line = await wisp.SendAsync(channel, "The jackpot is open.", card);await wisp.EditAsync(line, "The jackpot is closed."); // the card staysawait wisp.ReactAsync(line, ":fire:");await wisp.DeleteAsync(line);await wisp.SetRolesAsync(server, user, add: [vip]);await wisp.KickAsync(server, user);await wisp.BanAsync(server, user);| Call | Does |
|---|---|
SendAsync(channel, text, card?) |
posts a line; returns its id. replyTo: makes it a reply |
EditAsync(line, ...) |
changes one of your wisp’s own lines. It changes only what it names: words alone keep the card |
ShowAsync(line, card or patch) |
a live frame on your own line, kept nowhere (Cards) |
ReactAsync(line, emoji, on?) |
adds a reaction, or takes it back with on: false |
DeleteAsync(line) |
deletes your own line, or anyone’s with Manage messages |
SetRolesAsync(server, user, add?, remove?) |
gives and takes roles, with Manage roles |
KickAsync(server, user), BanAsync(server, user) |
with Kick members or Ban members |
SetActivityAsync(words) |
your wisp’s own words, such as “Dealing blackjack”, shown under its name as a person’s status is |
const line = await wisp.send(channel, "The jackpot is open.", card);await wisp.edit(line, "The jackpot is closed."); // the card staysawait wisp.react(line, ":fire:");await wisp.delete(line);await wisp.setRoles(server, user, { add: [vip] });await wisp.kick(server, user);await wisp.ban(server, user);| Call | Does |
|---|---|
send(channel, text, card?, { replyTo? }) |
posts a line; returns its id. replyTo makes it a reply |
edit(line, ...) |
changes one of your wisp’s own lines. It changes only what it names: words alone keep the card |
show(line, card or patch) |
a live frame on your own line, kept nowhere (Cards) |
react(line, emoji, { on? }) |
adds a reaction, or takes it back with { on: false } |
delete(line) |
deletes your own line, or anyone’s with Manage messages |
setRoles(server, user, { add?, remove? }) |
gives and takes roles, with Manage roles |
kick(server, user), ban(server, user) |
with Kick members or Ban members |
setActivity(words) |
your wisp’s own words, such as “Dealing blackjack”, shown under its name as a person’s status is |
A card comes off a line only with the line: delete it.
What it is allowed to do
Section titled “What it is allowed to do”What your wisp may do in a server is what its admin approved there: posting and reacting in the channels it works in, and managing roles, kicking and banning with the permissions it was given (How a server lets it in). Those permissions sit on a role made for your wisp, so it can only act on members and roles below that role, as any member can.
A call outside that throws with why it was refused, so branch on it:
try{ await wisp.KickAsync(server, user);}catch (WispCallException e) when (e.Why is Refusal.Permission or Refusal.NotGranted){ await run.AnswerPrivatelyAsync("I'm not allowed to kick here.");}try { await wisp.kick(server, user);} catch (error) { if (!(error instanceof WispCallError && (error.why === "permission" || error.why === "not_granted"))) throw error; await run.answerPrivately("I'm not allowed to kick here.");}C# e.Why |
TypeScript error.why |
Means |
|---|---|---|
Refusal.NotGranted |
"not_granted" |
outside what the admin approved, such as a channel it does not work in |
Refusal.Permission |
"permission" |
its roles, or the person’s, do not allow it |
Refusal.NotFound |
"not_found" |
the line, member, channel or role is not there |
Refusal.Invalid |
"invalid" |
the call breaks a rule; Woosh’s words say which |
Woosh’s own words, such as “Missing permission: KickMembers.”, are there for your log (e.Words;
in TypeScript, error.words). They may change, so write what people see from why.
A line is never posted twice
Section titled “A line is never posted twice”A call that may or may not have gone through, because the connection dropped at that moment, is sent again by the library in a way that never posts twice. You never need to check whether a line landed before sending it again.
Writing your own library? The frames underneath are in Acting in a server, raw.