0

Silence a user

by
Published Oct 17, 2025
Script discourse Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Discourse = {
3
  apiKey: string;
4
  defaultHost: string;
5
  apiUsername: string;
6
};
7
/**
8
 * Silence a user
9
 *
10
 */
11
export async function main(
12
  auth: Discourse,
13
  id: string,
14
  body: {
15
    silenced_till: string;
16
    reason: string;
17
    message?: string;
18
    post_action?: string;
19
  },
20
) {
21
  const url = new URL(`https://${auth.defaultHost}/admin/users/${id}/silence.json`);
22

23
  const response = await fetch(url, {
24
    method: "PUT",
25
    headers: {
26
      "Content-Type": "application/json",
27
      "API-KEY": auth.apiKey,
28
      "API-USERNAME": auth.apiUsername,
29
    },
30
    body: JSON.stringify(body),
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38