HTTP
These functions perform outbound HTTP GET requests from within a custom command. They are a self-host addition and are not present in upstream YAGPDB.
http/https schemes only.
Requests are SSRF-protected: the target host is resolved and connections to private, loopback, CGNAT, link-local
(including cloud metadata 169.254.169.254) and IPv6 ULA addresses are refused β so a custom command
cannot reach Docker-internal services such as the bot's own database or Redis.
There is no URL allow-list; any public URL is permitted, filtered only by the SSRF guard.
httpGet and httpGetJSON share a combined limit of 10 calls per custom command
execution (60 on premium), counter http_get. Requests are sent with
User-Agent: YAGPDB-selfhost/1.0 (httpGet template fn).
httpGet
{{ $body := httpGet <url> }}
Performs an HTTP GET request to url and returns the response body as a string. Returns an error if the
response status is 400 or greater, if the body exceeds 1 MB, or if the URL fails validation (scheme / host /
SSRF). The returned string is additionally bounded by the maximum string length.
httpGetJSON
{{ $data := httpGetJSON <url> }}
Like httpGet, but parses the response body as JSON and returns a navigable value: an sdict
for JSON objects and a slice for JSON arrays, so you can traverse it with .Field access or the
index function. Returns an error on a status of 400 or greater, or on invalid JSON.
{{ $data := httpGetJSON "https://example.com/champions.json" }}
{{ $champ := index $data.champions "aatrox" }}
{{ $champ.name }}
Member β Voice Moderation
These functions allow custom commands to manage voice channel members directly: move them between
voice channels, disconnect them, server-mute / unmute, and server-deafen / undeafen. They complement the read-only
getMemberVoiceState helper.
MOVE_MEMBERS for
moveMember, MUTE_MEMBERS for muteMember/unmuteMember, and
DEAFEN_MEMBERS for deafenMember/undeafenMember. The bot must also be higher
in the role hierarchy than the target member.
try/catch to
handle this gracefully.
voice_mod,
cost 1 each). Discord also enforces its own per-route rate limits on guild member modifications.
moveMember
{{ moveMember <target> <channel> }}
Moves a member to the specified voice channel. Pass nil or 0 as the channel argument to
disconnect the member from voice instead of moving them.
target: a user ID, mention, or user object. Must be in the server and currently connected to a voice channel.channel: destination voice channel β accepts an ID, name, or channel object.nil/0disconnects.
muteMember
{{ muteMember <target> }}
Server-mutes the specified member. The target must currently be in a voice channel.
target: a user ID, mention, or user object.
unmuteMember
{{ unmuteMember <target> }}
Removes a server-mute from the specified member.
target: a user ID, mention, or user object.
deafenMember
{{ deafenMember <target> }}
Server-deafens the specified member. The target must currently be in a voice channel.
target: a user ID, mention, or user object.
undeafenMember
{{ undeafenMember <target> }}
Removes a server-deafen from the specified member.
target: a user ID, mention, or user object.
Examples
Move a member to the AFK channel:
{{ if not (hasPermissions .Permissions.MoveMembers) }}
You do not have permission to move members.
{{ return }}
{{ end }}
{{ $args := parseArgs 1 "" (carg "member" "target") }}
{{ $target := ($args.Get 0).User }}
{{ $vs := getMemberVoiceState $target }}
{{ if not $vs }}
{{ printf "%s is not currently in a voice channel." $target.Mention }}
{{ return }}
{{ end }}
{{ try }}
{{ moveMember $target .Guild.AfkChannelID }}
{{ printf "%s was moved to the AFK channel." $target.Mention }}
{{ catch }}
Error: {{ .Error }}
{{ end }}
Disconnect a member from voice:
{{ moveMember .User nil }}
Toggle mute on the triggering user:
{{ $vs := getMemberVoiceState .User }}
{{ if not $vs }}Not in voice.{{ return }}{{ end }}
{{ if $vs.Mute }}
{{ unmuteMember .User }}Unmuted {{ .User.Mention }}.
{{ else }}
{{ muteMember .User }}Muted {{ .User.Mention }}.
{{ end }}
Voice State (data type)
Available as the return value of getMemberVoiceState and as the elements of
.Guild.VoiceStates (type discordgo.VoiceState). getMemberVoiceState returns
nil if the member is not connected to a voice channel.
| Field | Description |
|---|---|
| .ChannelID | The ID of the voice channel the member is connected to, of type int64. |
| .UserID | The ID of the member this voice state belongs to, of type int64. |
| .GuildID | The guild ID on which the voice state exists, of type int64. |
| .SessionID | The voice session ID, of type string. |
| .Mute | Whether the member is server-muted (bool). Set / cleared by muteMember/unmuteMember. |
| .Deaf | Whether the member is server-deafened (bool). Set / cleared by deafenMember/undeafenMember. |
| .SelfMute | Whether the member muted themselves (bool). |
| .SelfDeaf | Whether the member deafened themselves (bool). |
| .SelfStream | Whether the member is streaming with Go Live (bool). |
| .SelfVideo | Whether the member has their camera turned on (bool). |
| .Suppress | Whether the member is suppressed, e.g. a stage-channel audience member (bool). |
{{ (getMemberVoiceState .User).Mute }} reports whether the triggering user is server-muted.
Members
Bulk-fetch guild members from the Discord API. Self-host addition, not present in upstream YAGPDB.
getGuildMembers
{{ getGuildMembers [key value ...] }}
Fetches members of the current guild from the Discord API and returns a slice of *discordgo.Member.
Called with no arguments it returns up to 25 members of the current guild. Arguments are passed as key/value pairs.
| Key | Description |
|---|---|
| limit | How many members to fetch. Default 25, minimum 1, maximum 10000. |
| after | Pagination β return members with an ID greater than this user ID. |
| guildid | Fetch from another guild instead of the current one. Bot admin only. |
{{ $members := getGuildMembers "limit" 100 }}
Fetched: {{ len $members }}
{{ range $members }}
{{ .User.Username }}
{{ end }}
guild_getMembers, cost 2 per call.
Direct Messages
In upstream YAGPDB sendDM can only DM the user who triggered the command. This fork
extends it so that when the first argument resolves to a user, the DM is sent to that arbitrary user.
sendDM
{{ sendDM <userID> <message> }} {{/* any user */}}
{{ sendDM <message> }} {{/* the triggering user */}}
Called with two or more arguments where the first resolves to a user (ID, mention, or user object), the message is
sent to that user (resolved via TargetUserID). Called with a single argument it falls back to the stock
behaviour and DMs the command invoker. The message may be a string or a cembed; nothing is sent if the
content is empty.
{{/* DM a specific user */}}
{{ sendDM 140574551087120384 "Someone just won the game!" }}
{{/* With a variable + printf */}}
{{ $owner := 140574551087120384 }}
{{ sendDM $owner (printf "%s won, code: %d" .User.Username (randInt 1000 9999)) }}
{{/* Stock behaviour: DM the invoker */}}
{{ sendDM "A private message just for you." }}
master branch) ship the stock
triggerer-only sendDM.