arda.nb01
Centipat
- Katılım
- 24 Ocak 2024
- Mesajlar
- 281
Daha fazla
- Cinsiyet
- Erkek
Merhaba, bir Discord botu geliştiriyorum amacım bir listede veya bir dosya türünden veri çekip yazdırması ama object reference not set to an instance of an object. Hatası alıyorum. Kodum:
C#:
public class CreatorsCommand : CommandModule<CommandContext>
{
private static readonly List<string> Creators = new List<string>
{
"Erder", "Arda", "Grk"
};
[Command("creators")]
public async Task ShowCreatorsAsync()
{
try.
{
if (Creators == null || !Creators.Any())
{
await Context.Channel.SendMessageAsync("Herhangi bir creator bulunamadı.");
return;
}
// Creator listesi.
string creatorText = "**🎨 Creators 🎨**\n\n";
creatorText += "**#** **İsim**\n";
creatorText += "---------------------\n";
for (int i = 0; i < Creators.Count; i++)
{
creatorText += $"**#{i + 1}** {Creators[i]}\n";
}
// Mesaj.
await Context.Channel.SendMessageAsync(creatorText);
}
catch (System.Exception ex)
{
// Hata durumunda.
await Context.Channel.SendMessageAsync($"Bir hata oluştu: {ex.Message}");
}
}
}