发送一个空消息,而不是嵌入 Discord.Net

huangapple go评论68阅读模式
英文:

Send an empty message instead of Embed Discord.Net

问题

我在标题中阐述了我的问题。

代码:

public static async Task Whois(SocketSlashCommand command)
{
    var guildUser = (SocketGuildUser)command.Data.Options.First().Value;
    var roleList = string.Join(",\n", guildUser.Roles.Where(x => !x.IsEveryone).Select(x => x.Mention));
    var embedBuiler = new EmbedBuilder()
        .WithAuthor(guildUser.ToString(), guildUser.GetAvatarUrl() ?? guildUser.GetDefaultAvatarUrl())
        .WithTitle("角色")
        .WithDescription(roleList)
        .WithColor(Color.Green)
        .WithCurrentTimestamp();

    await command.RespondAsync(embed: embedBuiler.Build());
}

响应:响应

我不知道该怎么做。谢谢你的帮助。

英文:

I stated my problem in the title.

code:

public static async Task Whois(SocketSlashCommand command)
{
    var guildUser = (SocketGuildUser)command.Data.Options.First().Value;
    var roleList = string.Join(",\n", guildUser.Roles.Where(x => !x.IsEveryone).Select(x => x.Mention));
    var embedBuiler = new EmbedBuilder()
        .WithAuthor(guildUser.ToString(), guildUser.GetAvatarUrl() ?? guildUser.GetDefaultAvatarUrl())
        .WithTitle("Roles")
        .WithDescription(roleList)
        .WithColor(Color.Green)
        .WithCurrentTimestamp();

    await command.RespondAsync(embed: embedBuiler.Build());
}

response: [response](https://i.stack.imgur.com/Y6tim.png "response")

I don't know what to do. Thank you for your help

答案1

得分: 0

可能的解决方案 1

首先,请确保您在 Discord 客户端中显示嵌入内容。
前往设置,在“文本和图像”下启用“在聊天中显示粘贴的嵌入和预览网站链接”设置。

可能的解决方案 2

正如一些 GitHub 问题所示,您还需要为您的机器人授予“嵌入链接”权限。(尽管似乎不影响斜杠命令的嵌入)

可能的解决方案 3

还有可能是另一个机器人从您的消息中删除了嵌入内容,因此您可能需要添加一个日志记录机器人(以检查谁删除了嵌入内容)或创建一个只有您的机器人的新公会。

这个问题很不可能出现在您的代码中,因为 Discord API 实际上不允许发送空消息。(尽管如果您将“_ _”作为消息内容发送,这是可能的)

英文:

Possible Solution 1

First, be sure that you show embeds in you discord client.
Go in your settings under Text & Images and activate the Show embeds and preview website links pasted into chat setting.

Possible Solution 2

As it seems in some GitHub issues you also have to give your bot the "Embed Link" permission. (Although this doesn't seem to affect slash commands embeds)

Possible Solution 3

It is also possible that another bot is removing the embed from you message, so you may want to add a logging bot (to check who is removing the embed) or create a new guild where only your bot is.


It's very unlikely that the problem is in your code, as the Discord API doesn't actually allow empty messages to be sent. (although it is possible, if you send for example _ _ as your message content)

huangapple
  • 本文由 发表于 2023年4月13日 18:28:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76004371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定