Helpers

Helpers

Bitwise permission flags. More details here.

source
has_permission(perms::Integer, perm::Permission) -> Bool

Determine whether a bitwise OR of permissions contains one Permission.

Example

julia> has_permission(0x0420, PERM_VIEW_CHANNEL)
true

julia> has_permission(0x0420, PERM_ADMINISTRATOR)
false

julia> has_permission(0x0008, PERM_MANAGE_ROLES)
true
source
permissions_in(m::Member, g::Guild, ch::DiscordChannel) -> Int64

Compute a Member's Permissions in a DiscordChannel.

source
Discord.replyFunction.
reply(
    c::Client,
    m::Message,
    content::Union{AbstractString, AbstractDict, NamedTuple, Embed};
    at::Bool=false,
) -> Future{Response}

Reply (send a message to the same DiscordChannel) to a Message. If at is set, then the message is prefixed with the sender's mention.

source
Discord.split_messageFunction.
split_message(text::AbstractString) -> Vector{String}

Split a message into 2000-character chunks, preserving formatting.

Examples

```jldoctest; setup=:(using Discord) julia> split_message("foo") 1-element Array{String,1}: "foo"

julia> split_message(repeat('.', 1995) * "hello, world")[2] "hello, world"

source
Discord.plaintextFunction.
plaintext(m::Message) -> String
plaintext(c::Client, m::Message) -> String

Get the Message contents with any User mentions replaced with their plaintext. If a Client is provided, DiscordChannels Role are also replaced. However, only channels and roles stored in state are replaced; no API requests are made.

source
Discord.upload_fileFunction.
upload_file(c::Client, ch::DiscordChannel, path::AbstractString; kwargs...) -> Message

Send a Message with a file Attachment. Any keywords are passed on to create_message.

source
Discord.set_gameFunction.
set_game(
    c::Client,
    game::AbstractString;
    type::Union{ActivityType, Int}=AT_GAME,
    since::Nullable{Int}=c.presence["since"],
    status::Union{PresenceStatus, AbstractString}=c.presence["status"],
    afk::Bool=c.presence["afk"],
    kwargs...,
) -> Bool

Shortcut for update_status to set the Client's Activity. Any additional keywords are passed into the activity section.

source
Discord.@fetchMacro.
@fetch [functions...] block

Wrap all calls to the specified CRUD functions (create, retrieve, update, and delete) with fetch inside a block. If no functions are specified, all CRUD functions are wrapped.

Examples

Wrapping all CRUD functions:

@fetch begin
    guild_resp = create(c, Guild; name="foo")
    guild_resp.ok || error("Request for new guild failed")
    channel_resp = retrieve(c, DiscordChannel, guild_resp.val)
end

Wrapping only calls to retrieve:

@fetch retrieve begin
    resp = retrieve(c, DiscordChannel, 123)
    future = create(c, Message, resp.val; content="foo")  # Behaves normally.
end
source
@fetchval [functions...] block

Identical to @fetch, but calls are wrapped with fetchval instead.

source
@deferred_fetch [functions...] block

Identical to @fetch, but Futures are not fetched until the end of the block. This is more efficient, but only works when there are no data dependencies in the block.

Examples

This will work:

@deferred_fetch begin
    guild_resp = create(c, Guild; name="foo")
    channel_resp = retrieve(c, DiscordChannel, 123)
end

This will not, because the second call is dependent on the first value:

@deferred_fetch begin
    guild_resp = create(c, Guild; name="foo")
    channels_resp = retrieve(c, DiscordChannel, guild_resp.val)
end
source
@deferred_fetchval [functions...] block

Identical to @deferred_fetch, but Futures have fetchval called on them instead of fetch.

source