Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bridge/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type Bdiscord struct {
userMemberMap map[string]*discordgo.Member
nickMemberMap map[string]*discordgo.Member

// Never send Discord's attachments as URLs, always download and re-upload them to the destination as regular files
alwaysDownloadFiles bool

// Webhook specific logic
useAutoWebhooks bool
transmitter *transmitter.Transmitter
Expand All @@ -57,6 +60,8 @@ func New(cfg *bridge.Config) bridge.Bridger {
b.nickMemberMap = make(map[string]*discordgo.Member)
b.channelInfoMap = make(map[string]*config.ChannelInfo)

b.alwaysDownloadFiles = b.GetBool("AlwaysDownloadFiles")

b.useAutoWebhooks = b.GetBool("AutoWebhooks")
if b.useAutoWebhooks {
b.Log.Debug("Using automatic webhooks")
Expand Down
39 changes: 35 additions & 4 deletions bridge/discord/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/davecgh/go-spew/spew"
"github.com/matterbridge-org/matterbridge/bridge/config"
"github.com/matterbridge-org/matterbridge/bridge/helper"
)

func (b *Bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelete) { //nolint:unparam
Expand Down Expand Up @@ -98,15 +99,45 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
return
}

rmsg := config.Message{Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg", UserID: m.Author.ID, ID: m.ID, Extra: make(map[string][]interface{})}

// add the url of the attachments to content
if len(m.Attachments) > 0 {
first := true
for _, attach := range m.Attachments {
m.Content = m.Content + "\n" + attach.URL
if b.alwaysDownloadFiles {
var url, name, caption string
var data *[]byte

url = attach.URL
name = attach.Filename

err = helper.HandleDownloadSize(b.Log, &rmsg, name, int64(attach.Size), b.General)
if err != nil {
return
}
data, err = helper.DownloadFile(url)
if err != nil {
return
}

if first {
caption = m.Content
if caption == "" {
caption = name
}
first = false
} else {
caption = ""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on discord only the first image can have a caption? Or am i missing something?

@Wohlstand Wohlstand Dec 4, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discord has one united caption for all the images sent in the pack. Probably I should merge them into list?

  • like
  • this

To make it display all the captions properly?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what should be the policy here, when there's a united caption for a bunch of attachments. Should we apply it only on the first attachment? On all attachments? In all cases, this is beyond this specific bridge so i'd be happy to merge anything, but we should definitely document that kind of expected behavior in the guide to write new bridges (and align existing ones with expectations).

}

helper.HandleDownloadData(b.Log, &rmsg, name, caption, "", data, b.General)
Comment thread
Wohlstand marked this conversation as resolved.
} else {
m.Content = m.Content + "\n" + attach.URL
}
}
}

rmsg := config.Message{Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg", UserID: m.Author.ID, ID: m.ID}

b.Log.Debugf("== Receiving event %#v", m.Message)

if m.Content != "" {
Expand Down Expand Up @@ -139,7 +170,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
}

// no empty messages
if rmsg.Text == "" {
if rmsg.Text == "" && len(rmsg.Extra["file"]) == 0 {
return
}

Expand Down
17 changes: 17 additions & 0 deletions docs/protocols/discord/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ Show `#xxxx` discriminator with `UseUserName`
UseDiscriminator=true
```

## AlwaysDownloadFiles

Any uploads will be always downloaded as files and re-uploaded to the destination
gateway or the mediaproxy if enabled instead of forwarding URLs to Discord's CDNs.
By default, any file uploads from Discord gets forwarded as a list URLs to the
Discord CDN.

Use this if direct use of Discord CDN leads inconveniences or just unavailable
directly due to various reasons.

- Setting: **OPTIONAL**, **RELOADABLE**
- Format: *boolean*
- Example:
```toml
AlwaysDownloadFiles=true
```

## WebhookURL

Specify WebhookURL. If given, will relay messages using the Webhook, which
Expand Down
Loading