Skip to content

Structures

AdamJames edited this page Feb 26, 2017 · 34 revisions

Note all structures include their original Discord object's attributes if not overwritten.

base(parent)

A base class for structures.

Methods
  • update(data) loops over data and sets all keys and their respective values to self.
  • __updated() used by inheritors to know when their data is updated.
Attributes
  • parent a parent structure.

User(client)

Represents a Discord user.

Methods
  • sendMessage(...) creates a DM channel if not present and calls its sendMessage method.
Attributes
  • channel a Channel structure representing a DM channel with the user.

Server(client)

Represents a Discord guild.

Methods
  • edit({...}) requires an object with any parameter to modify.
    • owner either an int representing an user ID or an User structure or setOwner(owner).
    • name a string representing new guild's name or setName(name).
    • region a string representing new guild's region or setRegion(region).
    • icon a string representing new guild's icon or setIcon(icon).
    • splash a string representing new guild's splash or setSplash(splash).
    • setAFKchannel(channel) requires either a channel ID or a Channel structure.
    • setAFKtimeout(timeout) requires an int in miliseconds.
  • delete() permanently deletes the guild from Discord. Note this is not reversible.
  • unban(user) requires either an user ID or an User structure.
  • getBans() requests and returns a Cache object containing all banned users as User structures.
  • getInvites() requests and returns a Cache object containing all invites as Invite structures.
  • createRole() creates a new guild role and returns a Role structure.
  • createChannel({...}) requires an object containing these parametters.
    • createTextChannel(name) creates a text channel.
    • createVoiceChannel(name[, bitrate]) creates a voice channel.
Attributes
  • bans a Cache object containing banned users as User structures.
  • roles a Cache object containing Role structures.
  • members a Cache object containing Member structures.
  • channels a Cache object containing Channel structures.
  • invites a Cache object containing Invite structures.
  • owner an User structure representing guild's owner.
  • afk_channel a Channel structure representing guild's AFK channel, if set.
  • embed_channel a Channel structure representing guild's embed channel, if set.
Role(server)

Represents a guild role.

Methods
  • edit({...}) requires an object containing attributes to change.
    • name a string representing desired new name or setName(name).
    • position an int representing desired new display position or setPosition(position).
    • color an int representing desired rgb color or setColor(color).
    • hoist a bool representing whether should the role be displayed separately in the sidebar or setHoist(hoist).
  • delete() deletes the role.
Attributes
  • permissions a Bitwise object.
Member(server)

Represents a guild member.

Methods
  • edit({...}) requires an object containing attributes to change.
    • nick a string representing member's nickname to set or setNickName(nick).
    • mute a bool representing whether the member is muted or setMuted(mute).
    • deaf a bool representing whether the member is deafened or setDeaf(deaf).
    • move(channel) with either an id or a Channel structure, representing a voice channel to move the member to.
    • roles an array of roles the member is assigned to.
  • kick() kicks the member.
  • ban(days) bans the member, days represents the number of days to delete messages for.
  • setRole(role) assigns the member a Role.
  • revokeRole(role) removes the member from a Role.
  • hasPermission(bit) returns whether the member has given permission bit.
Attributes
  • user an User object representing the member.
  • roles an array containing Role structures.

Channel(parent)

Represents a Discord channel/DM. parent can be an User or a Server.

Methods
  • edit({...}) requires an object containing attributes to change.
    • name a string or setName(name).
    • topic a string or setTopic(topic).
    • bitrate an int or setBitrate(bitrate).
    • position an int or setPosition(position).
    • setSlots an int or setSlots(slots).
  • getHistory(limit[, config]) fetches and returns all messages based on given values and configuration.
  • sendMessage(thing) returns a Message structure, thing may be a string or an object with attributes.
  • bulkDelete(array) bulk-deletes all messages, as structures or IDs, in a given array.
  • getInvites() equivalent to server's but channel-level.
  • createInvite([{...}]) returns an Invite structure, optionally accepts an object with any valid parameter set.
  • delete() permanently deletes the channel.
Attributes
  • invites a Cache object containing invites as Invite structures.
  • history a Cache object of sent messages as Message structures.
  • is_voice a bool set to true in case it is a voice channel.
  • is_private a bool set to true in case it is a DM channel.
  • overwrites a Cache object containing Overwrite objects.
Message(channel)

Represents a Discord message.

Methods
  • reply(thing) calls message's parent channel's sendMessage method and returns a Message structure.
  • edit(thing) changes message's attributes, works the same way as sendMessage.
  • react(emoji) adds a reaction with given emoji and returns a Reaction structure.
  • delete() deletes the message.
Attributes
  • clean a string with all mentions fixed, i.e. if an user is mentioned their name is shown instead.
  • author an User structure representing message's author.
  • mentions an array containing mentioned users as User structures.
  • mentions.client a bool representing whether the local client is mentioned.
Reaction(message)

Represents a reaction to a message. Inherits from Emoji.

Methods
  • clear() clears a reaction.
  • remove([user]) removes a reaction from a given user or local's if not set.
Attributes
  • users a Cache object of User structures.
Emoji()

Represents an emoji.

Attributes
  • url a link to emoji's image.
  • string a string to be used in messages.
Overwrite(channel)

Represents a Discord channel permission overwrite.

Methods
  • delete() deletes the overwrite.
Attributes
  • deny a Bitwise object of denied permissions.
  • allow a Bitwise object of allowed permissions.
Invite(channel)

Represents a Discord channel invite.

Methods
  • accept() accepts the invite. Refer to client's acceptInvite method for direct acceptance.
  • delete() deletes the invite.
Attributes
  • url a string repesenting a direct link for the invite.

Bitwise(parent)

A management class for permissions. parent should always be an Overwrite or a Role object.

Methods
  • has(name) returns a bool representing whether input permission is added.
  • add(name) adds a permission from valid permissions. Also accepts a bit instead.
  • remove(name) removes a permission from valid permissions.