mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-22 10:55:15 -04:00
parent
cc1ad8b435
commit
06a4b6a8e6
3 changed files with 19 additions and 1 deletions
|
@ -10,7 +10,7 @@ using JsonExtensions.Reading;
|
||||||
namespace DiscordChatExporter.Core.Discord.Data;
|
namespace DiscordChatExporter.Core.Discord.Data;
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/channel#message-object
|
// https://discord.com/developers/docs/resources/channel#message-object
|
||||||
public record Message(
|
public partial record Message(
|
||||||
Snowflake Id,
|
Snowflake Id,
|
||||||
MessageKind Kind,
|
MessageKind Kind,
|
||||||
User Author,
|
User Author,
|
||||||
|
@ -26,6 +26,16 @@ public record Message(
|
||||||
IReadOnlyList<User> MentionedUsers,
|
IReadOnlyList<User> MentionedUsers,
|
||||||
MessageReference? Reference,
|
MessageReference? Reference,
|
||||||
Message? ReferencedMessage) : IHasId
|
Message? ReferencedMessage) : IHasId
|
||||||
|
{
|
||||||
|
public bool IsEmpty =>
|
||||||
|
Kind == MessageKind.Default &&
|
||||||
|
string.IsNullOrEmpty(Content) &&
|
||||||
|
!Attachments.Any() &&
|
||||||
|
!Embeds.Any() &&
|
||||||
|
!Stickers.Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial record Message
|
||||||
{
|
{
|
||||||
private static IReadOnlyList<Embed> NormalizeEmbeds(IReadOnlyList<Embed> embeds)
|
private static IReadOnlyList<Embed> NormalizeEmbeds(IReadOnlyList<Embed> embeds)
|
||||||
{
|
{
|
||||||
|
|
|
@ -323,6 +323,11 @@ public class DiscordClient
|
||||||
if (message.Timestamp > lastMessage.Timestamp)
|
if (message.Timestamp > lastMessage.Timestamp)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
|
// Make sure the messages are not empty when exporting via a bot
|
||||||
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/918
|
||||||
|
if (_resolvedTokenKind == TokenKind.Bot && message.IsEmpty && !message.Author.IsBot)
|
||||||
|
throw DiscordChatExporterException.MessageContentIntentMissing();
|
||||||
|
|
||||||
// Report progress based on the duration of exported messages divided by total
|
// Report progress based on the duration of exported messages divided by total
|
||||||
if (progress is not null)
|
if (progress is not null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,4 +41,7 @@ Failed to perform an HTTP request.
|
||||||
|
|
||||||
internal static DiscordChatExporterException ChannelIsEmpty() =>
|
internal static DiscordChatExporterException ChannelIsEmpty() =>
|
||||||
new("No messages found for the specified period.");
|
new("No messages found for the specified period.");
|
||||||
|
|
||||||
|
internal static DiscordChatExporterException MessageContentIntentMissing() =>
|
||||||
|
new("Failed to retrieve message content because the bot doesn't have the Message Content Intent enabled.");
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue