mattermost-community/focalboard · error
cannot get direct channel: %w
Error message
cannot get direct channel: %w
What it means
MentionDeliver returns this error when getDirectChannel fails to create or fetch the direct message channel between the bot and the mentioned user via the Mattermost plugin API. Without the channel the mention DM cannot be posted. The underlying plugin API error is wrapped with %w.
Source
Thrown at server/services/notify/plugindelivery/mention_deliver.go:24
import (
"fmt"
"github.com/mattermost/focalboard/server/services/notify"
"github.com/mattermost/focalboard/server/utils"
mm_model "github.com/mattermost/mattermost/server/public/model"
)
// MentionDeliver notifies a user they have been mentioned in a blockv ia the plugin API.
func (pd *PluginDelivery) MentionDeliver(mentionedUser *mm_model.User, extract string, evt notify.BlockChangeEvent) (string, error) {
author, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)
if err != nil {
return "", fmt.Errorf("cannot find user: %w", err)
}
channel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)
if err != nil {
return "", fmt.Errorf("cannot get direct channel: %w", err)
}
link := utils.MakeCardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID, evt.Card.ID)
boardLink := utils.MakeBoardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID)
post := &mm_model.Post{
UserId: pd.botID,
ChannelId: channel.Id,
Message: formatMessage(author.Username, extract, evt.Card.Title, link, evt.BlockChanged, boardLink, evt.Board.Title),
}
if _, err := pd.api.CreatePost(post); err != nil {
return "", err
}
return mentionedUser.Id, nil
}
View on GitHub (pinned to a84bbb65e3)
Solutions
- Verify the mentioned user is active and can receive DMs
- Check the bot account has permissions to create direct channels
- Inspect the wrapped cause (errors.As/Is) for the plugin API error details
- Confirm plugin/bot configuration in Mattermost system console
Example fix
// before
channel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)
if err != nil {
return "", fmt.Errorf("cannot get direct channel: %w", err)
}
// after
channel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)
if err != nil {
if model.IsErrNotFound(err) {
return "", nil // user cannot receive DMs; skip silently
}
return "", fmt.Errorf("cannot get direct channel: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// ensure mentioned user is active before mention delivery
mentioned, err := pd.api.GetUser(mentionedUser.Id)
if err != nil || mentioned.DeleteAt != 0 {
// skip: user cannot receive DMs
} Type guard
func canReceiveDM(u *mm_model.User) bool {
return u != nil && u.DeleteAt == 0
} Try / catch
msg, err := pd.MentionDeliver(mentionedUser, extract, evt)
if err != nil {
var targetErr error
if errors.As(err, &targetErr) && model.IsErrNotFound(targetErr) {
return "", nil // no DM possible; skip silently
}
return "", err
} Prevention
- Verify the bot account has permissions to create DM channels
- Skip delivery for deactivated/archived mentioned users
- Ensure plugin completes OnActivate before handling notify events
- Check Mattermost server connectivity if channel creation fails in bursts
When it happens
Trigger: A mentioned user is valid but the plugin cannot open a direct channel: the mentioned user is deactivated, the bot user lacks permission to create DM channels, or the Mattermost plugin API call fails (server unreachable, rate limited).
Common situations: Deactivated or archived mentioned users; bot account misconfiguration (missing bot role/permissions); Mattermost server restarts or plugin API latency; LDAP/SAML-synced users not yet provisioned locally.
Related errors
- cannot find user: %w
- cannot fetch channel member for user %s: %w
- mention not permitted
- invalid subscriber type
- cannot notify block subscribers for block %s: %w
AI-assisted analysis of mattermost-community/focalboard@a84bbb65e3 (2026-08-30).
Data as JSON: /api/errors/9ae85e1da767274d.
Report an issue: GitHub.