Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: CreatePostWithFileAsync Throws Error for Forums that Require Tags #2917

Open
3 tasks done
PoisonPrincess opened this issue Apr 27, 2024 · 0 comments
Open
3 tasks done
Labels
bug Needs investigation Needs to be looked at by a maintainer

Comments

@PoisonPrincess
Copy link

PoisonPrincess commented Apr 27, 2024

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

Reproduction:

Steps:

  1. Create a forum (#testforum) channel with at least one tag.
  2. Check Require people to select tags when posting in #testforum.
  3. Create ForumTag[] tags containing one valid ForumTag from #testforum.
  4. Use CreatePostWithFileAsync(title, stream, fileName, archiveDuration, text, embed, tags) to create a post in #testforum.

Expected Result:

A post is made in #testforum with the text, archive duration, tag, and embed featuring the image.

Result:

CreatePostWithFileAsync() throws exception: System.AggregateException: 'One or more errors occurred. (The channel testforum requires posts to have at least one tag.)'.


Further Info:

Steps:

  1. Uncheck Require people to select tags when posting in #testforum.
  2. Create ForumTag[] tags containing the same ForumTag from #testforum as before.
  3. Use CreatePostWithFileAsync(title, stream, fileName, archiveDuration, text, embed, tags) to create a post in #testforum.

Result:

A post is made in #testforum with the text, archive duration, tag, and embed featuring the image.
Despite the error that occurs when the forum requires tags implying that the tags are being skipped or ignored, they still show up when the post is created, meaning that the AggregateException is being thrown incorrectly.

Version

3.14.1

Logs

System.AggregateException: 'One or more errors occurred. (The channel testforum requires posts to have at least one tag.)'

Sample

Try first with tags required, then try again with tags optional.

ulong serverID, forumChannelID; //set to applicable values

//Get stream
string imgLink = "https://napchart.com/api/v2/getImage?chartid=motsliO4P"; //set to url for a png, I used this for testing
WebRequest request = WebRequest.Create(imgLink);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
string fileName = "img.png";

EmbedBuilder embed = new() { Title = "test" };

//get forum
SocketForumChannel forum = Bot.getSocketGuild(serverID).GetForumChannel(forumChannelID);
//get a tag from forum
ForumTag[] tags = forum.Tags.Where(t => t.Name.ToLower().Contains("sampleTag")).ToArray();

try
{
	//Try with CreatePostWithFileAsync
	await forum.CreatePostWithFileAsync("CreatePostWithFileAsync Test", stream, fileName, archiveDuration: ThreadArchiveDuration.ThreeDays,
		text: "This is with FileAsync; currently only works when tags are disabled", 
		embed: embed.WithImageUrl($"attachment://{fileName}").Build(), tags: tags);
}
catch (Exception e)
{
	Debug.WriteLine(e.Message);
}

try
{
	//Try with CreatePostAsync
	await forum.CreatePostAsync("CreatePostAsync Test", ThreadArchiveDuration.ThreeDays,
		text: "This is without FileAsync; currently works when tags are enabled or disabled",
		embed: embed.WithImageUrl(imgLink).Build(), tags: tags);
}
catch (Exception e)
{
	Debug.WriteLine(e.Message);
}

Packages

Discord.Net (13.14.1)

Environment

  • OS: Windows 11 Pro 24H2 26100.1
  • Architecture: x64
  • SDK: .NET 6.0
@Misha-133 Misha-133 added the Needs investigation Needs to be looked at by a maintainer label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs investigation Needs to be looked at by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants