#Attachements

1 messages · Page 1 of 1 (latest)

somber hemlock
#

when I try to copy message then re write it with bot attachment doesn't appear on the bot message I can't even fetch it from old message to message builder

await ctx.Channel.SendMessageAsync(embedmessage.ToString());
somber aspen
#

There's a lot of things that are being done wrong here, but before we address those, let's fix the main problem

#

eval ```cs
await context.RespondAsync("...");
DiscordMessage message = await context.Channel.GetMessageAsync(1291937235381522493);
await context.FollowupAsync(message.ToString());

thick domeBOT
#

Message 1291937235381522493; Attachment count: 0; Embed count: 0; Contents: when I try to copy message then re write it with bot attachment doesn't appear on the bot message I can't even fetch it from old message to message builder

await ctx.Channel.SendMessageAsync(embedmessage.ToString());
somber aspen
#

So, as you can see above

#

DiscordMessage.ToString() returns a debug view of the message's properties

#

If you want to copy a message, I recommend using either new DiscordMessageBuilder(DiscordMessage message) to copy the message

#

Or wait until message forwarding releases to the library

#

As above ^^

somber aspen
#

Files do not get copied over

#

And part of that is because Discord's attachment system is a little weird

#

So if you want to copy a file, you can't just reference the file, you have to reupload it completely

#

Which comes with it's own caveats: Bots have a default file limit of 10mb unless if the server boost level is high enough to allow for 100mb uploads

#

I could be wrong on those limits, they change every so often

#

This is how I "copy" a message and paste it to a new channel

#

If that command is what you're trying to do, let it be known that there are known bugs within my implementation

#

Now let's break this down: ```cs
embedmessage = await channel.GetMessageAsync(Convert.ToUInt64(message));
await ctx.Channel.SendMessageAsync(embedmessage.ToString());

#

Convert.ToUInt64
Firstly, there's three ways of doing this, none of which should you use Convert:

  • ulong.Parse(messageId)
  • (ulong)messageId*
    • Will not work with strings
  • public async ValueTask ExecuteAsync(CommandContext context, ulong messageId)
    • You can just request the message id as a ulong from your command through the commands extension, which will handle the argument conversion process for you
#

Actually, which commands extension are you using?

  • CommandsNext
  • SlashCommands
  • Commands
    • This is the newest extension that will be replacing the previous two extensions within the coming months
#

@somber hemlock, I hope this helps blobLove

somber hemlock
#

private Stream GetHttpStreamRequest(string url) => WebRequest.Create(url).GetResponse().GetResponseStream();
that's all I need to get stream from attachement to add it to files in my message builder system

#

thanks you so much ❤️

small roost
#

WebRequest is deprecated, use an HttpClient instead

crimson forge
#

Also you should use async/await for performance reasons

deft oriole
#

WebRequest predates that, iirc

crimson forge
#

another reason to switch when

somber hemlock
#
{
    if (string.IsNullOrEmpty(url)) throw new ArgumentException("URL cannot be null or empty.");
    return await new HttpClient().GetStreamAsync(url);
}```
#

yep that's much better

deft oriole
#

use a static http client, but aside from that, yes

somber aspen
#

Alternatively