discordclient

package module
v0.0.0-...-165fc2e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2021 License: MIT Imports: 8 Imported by: 4 modules, 7 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

discordclient

Documentation

Index

Constants

View Source
const (
	// MessageTypeCreate is the message type for message creation.
	MessageTypeCreate MessageType = "create"
	// MessageTypeUpdate is the message type for message updates.
	MessageTypeUpdate = "update"
	// MessageTypeDelete is the message type for message deletion.
	MessageTypeDelete = "delete"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DiscordClient

type DiscordClient struct {
	Session        *discordgo.Session
	User           *discordgo.User
	Sessions       []*discordgo.Session
	OwnerUserID    string
	ClientID       string
	AllowBots      bool
	GatewayIntents discordgo.Intent
	// contains filtered or unexported fields
}

DiscordClient handles discord sessions and client configurations

func NewDiscordClient

func NewDiscordClient(discordToken string, ownerClientID string, discordClientID string) *DiscordClient

NewDiscordClient returns a new instance of DiscordClient

func (*DiscordClient) BanUser

func (d *DiscordClient) BanUser(channel, userID string, duration int) error

BanUser bans a user for a specified duration

func (*DiscordClient) Channel

func (d *DiscordClient) Channel(channelID string) (channel *discordgo.Channel, err error)

Channel resolves a Channel object from a channelID

func (*DiscordClient) ChannelCount

func (d *DiscordClient) ChannelCount() int

ChannelCount returns the number of channels the client is connected to

func (*DiscordClient) DeleteMessage

func (d *DiscordClient) DeleteMessage(channel, messageID string) error

DeleteMessage deletes a discord message

func (*DiscordClient) GetMessages

func (d *DiscordClient) GetMessages(channelID string, limit int, beforeID string) ([]Message, error)

GetMessages returns a list of messages for a channel

func (*DiscordClient) Guild

func (d *DiscordClient) Guild(guildID string) (guild *discordgo.Guild, err error)

Guild resolves a Guild object from a guildID

func (*DiscordClient) GuildMember

func (d *DiscordClient) GuildMember(userID, guildID string) (*discordgo.Member, error)

GuildMember resolves a guild member based on a userID and guildID.

func (*DiscordClient) Guilds

func (d *DiscordClient) Guilds() []*discordgo.Guild

Guilds returns an arrray of Guilds the client is connected to

func (*DiscordClient) IsBotOwner

func (d *DiscordClient) IsBotOwner(message Message) bool

IsBotOwner checks if a message is from the configured bot owner

func (*DiscordClient) IsChannelOwner

func (d *DiscordClient) IsChannelOwner(message Message) bool

IsChannelOwner checks if the message is from the Guild admin

func (*DiscordClient) IsMe

func (d *DiscordClient) IsMe(message Message) bool

IsMe checks if the message has the same id as this session

func (*DiscordClient) IsModerator

func (d *DiscordClient) IsModerator(message Message) bool

IsModerator checks if the message is from a Guild moderator

func (*DiscordClient) IsPrivate

func (d *DiscordClient) IsPrivate(message Message) bool

IsPrivate checks if a message is being sent from a direct message

func (*DiscordClient) Join

func (d *DiscordClient) Join(join string) error

Join forces the client to join a guild based on an invite ID

func (*DiscordClient) Listen

func (d *DiscordClient) Listen(shardCount int) (<-chan Message, error)

Listen to the websocket using the specified number of shards. -1 to use recommended number.

func (*DiscordClient) ListenConfigure

func (d *DiscordClient) ListenConfigure(shardCount int, shardID int) (<-chan Message, error)

ListenConfigure to the websocket using a single shard with a specific configuration.

func (*DiscordClient) MessageHistory

func (d *DiscordClient) MessageHistory(channel string) []Message

MessageHistory returns the last x number of messages from a channel

func (*DiscordClient) Nickname

func (d *DiscordClient) Nickname(message Message) string

Nickname resolves a users nickname based on a message

func (*DiscordClient) NicknameForID

func (d *DiscordClient) NicknameForID(userID, userName, channelID string) string

NicknameForID resolves a users nickname based on a userId with a fallback username

func (*DiscordClient) Open

func (d *DiscordClient) Open() error

Open a connection

func (*DiscordClient) PrivateMessage

func (d *DiscordClient) PrivateMessage(userID string, message string) error

PrivateMessage sends a private message to a user

func (*DiscordClient) SendEmbedMessage

func (d *DiscordClient) SendEmbedMessage(channel string, message *discordgo.MessageEmbed) error

SendEmbedMessage sends an embed discord message

func (*DiscordClient) SendFile

func (d *DiscordClient) SendFile(channel, name string, r io.Reader) error

SendFile sends a file to a discord channel

func (*DiscordClient) SendMessage

func (d *DiscordClient) SendMessage(channel string, message string) error

SendMessage sends a discord message

func (*DiscordClient) Typing

func (d *DiscordClient) Typing(channel string) error

Typing makes makes it appear that the client is typing in a specified Channel

func (*DiscordClient) UnbanUser

func (d *DiscordClient) UnbanUser(channel, userID string) error

UnbanUser unbans a user

func (*DiscordClient) UserChannelPermissions

func (d *DiscordClient) UserChannelPermissions(userID, channelID string) (apermissions int64, err error)

UserChannelPermissions returns the permissions for a user in a channel

func (*DiscordClient) UserColor

func (d *DiscordClient) UserColor(userID, channelID string) int

UserColor returns the color code for a user in a channel

func (*DiscordClient) UserCount

func (d *DiscordClient) UserCount() int

UserCount returns the number of users the client is connected to

func (*DiscordClient) UserID

func (d *DiscordClient) UserID() string

UserID the UserID of the client

func (*DiscordClient) UserName

func (d *DiscordClient) UserName() string

UserName gets the username of the client

type DiscordMessage

type DiscordMessage struct {
	Discord          *DiscordClient
	DiscordgoMessage *discordgo.Message
	MessageType      MessageType
	Nick             *string
	Content          *string
	// contains filtered or unexported fields
}

DiscordMessage holds received message information

func (*DiscordMessage) Channel

func (m *DiscordMessage) Channel() string

Channel returns the message channel id

func (*DiscordMessage) IsBot

func (m *DiscordMessage) IsBot() bool

IsBot returns true if the message author is a bot. This will always be false if DiscordClient.AllowBots is false.

func (*DiscordMessage) IsMentionPrefix

func (m *DiscordMessage) IsMentionPrefix() (string, bool)

IsMentionPrefix returns true when the client user is the first part of the message

func (*DiscordMessage) IsMentionTrigger

func (m *DiscordMessage) IsMentionTrigger(trigger string) (bool, string)

IsMentionTrigger returns true when the client user is the first part of the message with a trigger word

func (*DiscordMessage) Message

func (m *DiscordMessage) Message() string

Message returns the message in human readable text

func (*DiscordMessage) MessageID

func (m *DiscordMessage) MessageID() string

MessageID gets the ID of the message

func (*DiscordMessage) RawMessage

func (m *DiscordMessage) RawMessage() string

RawMessage gets the raw message

func (*DiscordMessage) ResolveGuildID

func (m *DiscordMessage) ResolveGuildID() (string, error)

ResolveGuildID resolves the GuildID from the message channel

func (*DiscordMessage) ResolveMessageChannel

func (m *DiscordMessage) ResolveMessageChannel() (*discordgo.Channel, error)

ResolveMessageChannel resolves the Channel from the message

func (*DiscordMessage) Timestamp

func (m *DiscordMessage) Timestamp() (time.Time, error)

Timestamp gets the timestamp of the message

func (*DiscordMessage) Type

func (m *DiscordMessage) Type() MessageType

Type gets the type of the message

func (*DiscordMessage) UserAvatar

func (m *DiscordMessage) UserAvatar() string

UserAvatar returns the url to the message senders avatar

func (*DiscordMessage) UserID

func (m *DiscordMessage) UserID() string

UserID returns the message userID

func (*DiscordMessage) UserName

func (m *DiscordMessage) UserName() string

UserName returns the message username

type Message

type Message interface {
	Channel() string
	UserName() string
	UserID() string
	UserAvatar() string
	Message() string
	RawMessage() string
	MessageID() string
	Type() MessageType
	Timestamp() (time.Time, error)
	ResolveGuildID() (string, error)
	ResolveMessageChannel() (*discordgo.Channel, error)
	IsMentionTrigger(string) (bool, string)
	IsBot() bool
}

Message defines discord message helpers

type MessageType

type MessageType string

MessageType is the type of Message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址