Discord-Net-Labs / Discord.Net-Labs

An experimental fork of Discord.Net that implements the newest discord features for testing and development to eventually get merged into Discord.Net
https://labs.discordnet.dev
MIT License
156 stars 42 forks source link

Can't create Threads in News (Announcement) channels. #296

Closed aggiczy closed 2 years ago

aggiczy commented 2 years ago

Hi there!

I've got this error message when I try to create a thread in a News Channel:

System.NullReferenceException: Object reference not set to an instance of an object.

My method:

(Context.Channel as SocketNewsChannel).CreateThreadAsync("test");

What is the problem in this? Can you fix it please?

Thanks, Aki26 GamePlay#3982

quinchs commented 2 years ago

Is there a stack trace with the exception?

aggiczy commented 2 years ago

Is there a stack trace with the exception?

Sorry but I don't know exactly what is stack trace. Maybe this?:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Submission#0.<<Initialize>>d__0.MoveNext()
quinchs commented 2 years ago

The reason for the excpetion is that Context.Channel is not a SocketNewsChannel, therfor casting it yields null.

aggiczy commented 2 years ago

But with ITextChannel I get the same error message.

Edit: With ITextChannel I don't get error but it don't create the thread.

aggiczy commented 2 years ago

So my question: How can I create threads in a News/Announcement channel?

quinchs commented 2 years ago

~Discord doesn't seem to allow bots to create threads in news~ image

quinchs commented 2 years ago

Disregard, as pointed out by @NovaFox161 you need to specify ThreadType.NewsThread when creating your thread. An example would be:

var chan = client.GetGuild(guildId).GetTextChannel(newsChannelId);
await chan.CreateThreadAsync("test", ThreadType.NewsThread);