C
C#16mo ago
SylveonDeko

❔ Im gonna lose my fucking mind over this

148 Replies
S-IERRA
S-IERRA16mo ago
whats wrong
SylveonDeko
SylveonDekoOP16mo ago
that^
Angius
Angius16mo ago
what
SylveonDeko
SylveonDekoOP16mo ago
channel is not null but it returns prematurely but doesnt touch the actual return;
S-IERRA
S-IERRA16mo ago
ur on ridewr?
SylveonDeko
SylveonDekoOP16mo ago
correct
S-IERRA
S-IERRA16mo ago
S-IERRA
S-IERRA16mo ago
igh sick run w debugger and hover over the variable for me
SylveonDeko
SylveonDekoOP16mo ago
its on lol
Angius
Angius16mo ago
It's really hard to say what's wrong by just seeing 3 lines of code
S-IERRA
S-IERRA16mo ago
can u hover over the var and show me what the values are
SylveonDeko
SylveonDekoOP16mo ago
now, why do you think im saying its not null?
onefuture
onefuture16mo ago
@new FuckPremiumBots() have you considered this
onefuture
onefuture16mo ago
PHP: Hypertext Preprocessor
PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.
S-IERRA
S-IERRA16mo ago
f10
blinkbat
blinkbat16mo ago
...why
Jimmacle
Jimmacle16mo ago
this is not a helpful suggestion
SylveonDeko
SylveonDekoOP16mo ago
wat.
S-IERRA
S-IERRA16mo ago
see what it says ah ok
onefuture
onefuture16mo ago
im guessing you are using discord.net right?
SylveonDeko
SylveonDekoOP16mo ago
yes
onefuture
onefuture16mo ago
GitHub
GitHub - discord-php/DiscordPHP: An API to interact with the popula...
An API to interact with the popular messaging app Discord - GitHub - discord-php/DiscordPHP: An API to interact with the popular messaging app Discord
S-IERRA
S-IERRA16mo ago
@new FuckPremiumBots() it could be that its failing to fetch the channel
onefuture
onefuture16mo ago
heres a better alternative
Jimmacle
Jimmacle16mo ago
are you trying to speedrun a ban?
SylveonDeko
SylveonDekoOP16mo ago
how
S-IERRA
S-IERRA16mo ago
S-IERRA
S-IERRA16mo ago
here
SylveonDeko
SylveonDekoOP16mo ago
im literally giving it the channel
S-IERRA
S-IERRA16mo ago
yes but discord is weird had the same issue in py
SylveonDeko
SylveonDekoOP16mo ago
[Cmd, Aliases, RequireContext(ContextType.Guild), UserPerm(GuildPermission.ManageMessages)]
public async Task GEnd(ulong messageid)
{
await using var uow = db.GetDbContext();
var gway = uow.Giveaways
.GiveawaysForGuild(ctx.Guild.Id).ToList().Find(x => x.MessageId == messageid);
if (gway is null)
await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!").ConfigureAwait(false);

if (gway.Ended == 1)
await ctx.Channel.SendErrorAsync(
$"This giveaway has already ended! Plase use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!").ConfigureAwait(false);
else
{
var channel = await Context.Guild.GetTextChannelAsync(gway.ChannelId);
if (channel is null)
{
await ctx.Channel.SendErrorAsync("Giveaway channel not found!").ConfigureAwait(false);
return;
}
await Service.GiveawayTimerAction(gway, channel.Guild, channel).ConfigureAwait(false);
await ctx.Channel.SendConfirmAsync("Giveaway ended!").ConfigureAwait(false);
}
}
[Cmd, Aliases, RequireContext(ContextType.Guild), UserPerm(GuildPermission.ManageMessages)]
public async Task GEnd(ulong messageid)
{
await using var uow = db.GetDbContext();
var gway = uow.Giveaways
.GiveawaysForGuild(ctx.Guild.Id).ToList().Find(x => x.MessageId == messageid);
if (gway is null)
await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!").ConfigureAwait(false);

if (gway.Ended == 1)
await ctx.Channel.SendErrorAsync(
$"This giveaway has already ended! Plase use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!").ConfigureAwait(false);
else
{
var channel = await Context.Guild.GetTextChannelAsync(gway.ChannelId);
if (channel is null)
{
await ctx.Channel.SendErrorAsync("Giveaway channel not found!").ConfigureAwait(false);
return;
}
await Service.GiveawayTimerAction(gway, channel.Guild, channel).ConfigureAwait(false);
await ctx.Channel.SendConfirmAsync("Giveaway ended!").ConfigureAwait(false);
}
}
S-IERRA
S-IERRA16mo ago
uhm can you try to run w/o debugger
SylveonDeko
SylveonDekoOP16mo ago
the method thats calling it ok
blinkbat
blinkbat16mo ago
oh finally a whole block of code
onefuture
onefuture16mo ago
almost blinded myself looking at that
SylveonDeko
SylveonDekoOP16mo ago
you aint gonna have no future if you keep being an attention seeking brat let alone 1future
S-IERRA
S-IERRA16mo ago
just ignore
blinkbat
blinkbat16mo ago
that code block doesn't look like the bug you experienced
SylveonDeko
SylveonDekoOP16mo ago
ik, just had to get that out
onefuture
onefuture16mo ago
ask chat gpt to optimize it
SylveonDeko
SylveonDekoOP16mo ago
ik, thats whats caling the method sec
public async Task GiveawayTimerAction(Database.Models.Giveaways r, IGuild inputguild = null, ITextChannel inputchannel = null)
{
var dclient = client as IDiscordClient;
var guild = inputguild ?? await dclient.GetGuildAsync(r.ServerId);
if (guild is null)
return;

var channel = inputchannel ?? await guild.GetTextChannelAsync(r.ChannelId);
if (channel is null)
return;
IUserMessage ch;
try
{
if (await channel.GetMessageAsync(r.MessageId).ConfigureAwait(false) is not
IUserMessage ch1)
{
return;
}

ch = ch1;
}
catch
{
return;
}

var prefix = await guildSettings.GetPrefix(guild.Id).ConfigureAwait(false);
public async Task GiveawayTimerAction(Database.Models.Giveaways r, IGuild inputguild = null, ITextChannel inputchannel = null)
{
var dclient = client as IDiscordClient;
var guild = inputguild ?? await dclient.GetGuildAsync(r.ServerId);
if (guild is null)
return;

var channel = inputchannel ?? await guild.GetTextChannelAsync(r.ChannelId);
if (channel is null)
return;
IUserMessage ch;
try
{
if (await channel.GetMessageAsync(r.MessageId).ConfigureAwait(false) is not
IUserMessage ch1)
{
return;
}

ch = ch1;
}
catch
{
return;
}

var prefix = await guildSettings.GetPrefix(guild.Id).ConfigureAwait(false);
this all stems from a previous jank issue lol
blinkbat
blinkbat16mo ago
it could be hitting any of those returns
SylveonDeko
SylveonDekoOP16mo ago
onefuture
onefuture16mo ago
[Cmd, Aliases, RequireContext(ContextType.Guild), UserPerm(GuildPermission.ManageMessages)]
public async Task GEnd(ulong messageid)
{
await using var uow = db.GetDbContext();
var gway = uow.Giveaways.GiveawaysForGuild(ctx.Guild.Id).FirstOrDefault(x => x.MessageId == messageid);

if (gway == null)
{
await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!").ConfigureAwait(false);
return;
}

if (gway.Ended == 1)
{
await ctx.Channel.SendErrorAsync(
$"This giveaway has already ended! Please use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!").ConfigureAwait(false);
return;
}

var channel = await Context.Guild.GetTextChannelAsync(gway.ChannelId);
if (channel == null)
{
await ctx.Channel.SendErrorAsync("Giveaway channel not found!").ConfigureAwait(false);
return;
}

await Service.GiveawayTimerAction(gway, channel.Guild, channel).ConfigureAwait(false);
await ctx.Channel.SendConfirmAsync("Giveaway ended!").ConfigureAwait(false);
}
[Cmd, Aliases, RequireContext(ContextType.Guild), UserPerm(GuildPermission.ManageMessages)]
public async Task GEnd(ulong messageid)
{
await using var uow = db.GetDbContext();
var gway = uow.Giveaways.GiveawaysForGuild(ctx.Guild.Id).FirstOrDefault(x => x.MessageId == messageid);

if (gway == null)
{
await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!").ConfigureAwait(false);
return;
}

if (gway.Ended == 1)
{
await ctx.Channel.SendErrorAsync(
$"This giveaway has already ended! Please use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!").ConfigureAwait(false);
return;
}

var channel = await Context.Guild.GetTextChannelAsync(gway.ChannelId);
if (channel == null)
{
await ctx.Channel.SendErrorAsync("Giveaway channel not found!").ConfigureAwait(false);
return;
}

await Service.GiveawayTimerAction(gway, channel.Guild, channel).ConfigureAwait(false);
await ctx.Channel.SendConfirmAsync("Giveaway ended!").ConfigureAwait(false);
}
SylveonDeko
SylveonDekoOP16mo ago
where for some reason channel was null
S-IERRA
S-IERRA16mo ago
yes like i said
SylveonDeko
SylveonDekoOP16mo ago
but that was only socket
S-IERRA
S-IERRA16mo ago
it could be failing to fetch it as a fallback value
SylveonDeko
SylveonDekoOP16mo ago
rest returns it fine
S-IERRA
S-IERRA16mo ago
missing intent most likley
SylveonDeko
SylveonDekoOP16mo ago
nope
S-IERRA
S-IERRA16mo ago
weird
SylveonDeko
SylveonDekoOP16mo ago
all intents on and configured
blinkbat
blinkbat16mo ago
debug after that line see the value of channel
SylveonDeko
SylveonDekoOP16mo ago
that code is long changed, channel is null becausse its null for some reason despite not being null in the calling method
blinkbat
blinkbat16mo ago
why would you send old code
SylveonDeko
SylveonDekoOP16mo ago
^
blinkbat
blinkbat16mo ago
do you have a bug or not
SylveonDeko
SylveonDekoOP16mo ago
yes
onefuture
onefuture16mo ago
[Cmd, Aliases, RequireContext(ContextType.Guild), UserPerm(GuildPermission.ManageMessages)]
public async Task GEnd(ulong messageid)
{
await using var uow = db.GetDbContext();
var giveaway = uow.Giveaways.GiveawaysForGuild(ctx.Guild.Id).FirstOrDefault(x => x.MessageId == messageid);

if (giveaway == null)
{
await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!");
return;
}

if (giveaway.Ended == 1)
{
await ctx.Channel.SendErrorAsync($"This giveaway has already ended! Use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!");
return;
}

var channel = await Context.Guild.GetTextChannelAsync(giveaway.ChannelId);
if (channel == null)
{
await ctx.Channel.SendErrorAsync("Giveaway channel not found!");
return;
}

await Service.GiveawayTimerAction(giveaway, channel.Guild, channel);
await ctx.Channel.SendConfirmAsync("Giveaway ended!");
}
[Cmd, Aliases, RequireContext(ContextType.Guild), UserPerm(GuildPermission.ManageMessages)]
public async Task GEnd(ulong messageid)
{
await using var uow = db.GetDbContext();
var giveaway = uow.Giveaways.GiveawaysForGuild(ctx.Guild.Id).FirstOrDefault(x => x.MessageId == messageid);

if (giveaway == null)
{
await ctx.Channel.SendErrorAsync("No Giveaway with that message ID exists! Please try again!");
return;
}

if (giveaway.Ended == 1)
{
await ctx.Channel.SendErrorAsync($"This giveaway has already ended! Use `{await guildSettings.GetPrefix(ctx.Guild)}greroll {messageid}` to reroll!");
return;
}

var channel = await Context.Guild.GetTextChannelAsync(giveaway.ChannelId);
if (channel == null)
{
await ctx.Channel.SendErrorAsync("Giveaway channel not found!");
return;
}

await Service.GiveawayTimerAction(giveaway, channel.Guild, channel);
await ctx.Channel.SendConfirmAsync("Giveaway ended!");
}
blinkbat
blinkbat16mo ago
can you like stop maybe
onefuture
onefuture16mo ago
...
Jimmacle
Jimmacle16mo ago
just report and move on
onefuture
onefuture16mo ago
im sending better code
SylveonDeko
SylveonDekoOP16mo ago
channel is NOT null here so im confused af
S-IERRA
S-IERRA16mo ago
@new FuckPremiumBots() im thinking it could be race contition related
SylveonDeko
SylveonDekoOP16mo ago
oh boy thats fun
S-IERRA
S-IERRA16mo ago
because if ur doing an async operation then its failing to fetch it in time then its ffailing on the if statement
SylveonDeko
SylveonDekoOP16mo ago
definitely possible
S-IERRA
S-IERRA16mo ago
because when you run it thru debugger it worked
SylveonDeko
SylveonDekoOP16mo ago
lovely what could the race condition be tho
S-IERRA
S-IERRA16mo ago
it wouldnt make sense tho cuz ur awaiting it
SylveonDeko
SylveonDekoOP16mo ago
the async methods dont run since i give the values and they arent null
S-IERRA
S-IERRA16mo ago
S-IERRA
S-IERRA16mo ago
on debugger can u check
SylveonDeko
SylveonDekoOP16mo ago
yeah
S-IERRA
S-IERRA16mo ago
wait u did nvm
SylveonDeko
SylveonDekoOP16mo ago
thats why channel isnt null im losing braincells trying to figure this out lmao
S-IERRA
S-IERRA16mo ago
write ITextChannel?
S-IERRA
S-IERRA16mo ago
even with IGuild
SylveonDeko
SylveonDekoOP16mo ago
yes
S-IERRA
S-IERRA16mo ago
im pretty sure thats the issue
SylveonDeko
SylveonDekoOP16mo ago
why would that be an issue Thonk
S-IERRA
S-IERRA16mo ago
isnt nullable and over c# 8 thats an issue
SylveonDeko
SylveonDekoOP16mo ago
it is Thonk you mean put a ?
S-IERRA
S-IERRA16mo ago
yes ITextChannel? inputChannel = null
SylveonDeko
SylveonDekoOP16mo ago
in which case it shouldnt matter because i do the same with my commands and it doesnt have an issue
S-IERRA
S-IERRA16mo ago
just try it see what it does
SylveonDeko
SylveonDekoOP16mo ago
alr
S-IERRA
S-IERRA16mo ago
if not what u can also do there should be a nullable over ride method HasValue when you make it nullable so set it to what i said above and then check if(inputChannel.HasValue)
SylveonDeko
SylveonDekoOP16mo ago
SylveonDeko
SylveonDekoOP16mo ago
same with inputchannel
S-IERRA
S-IERRA16mo ago
ignore that then but ud put that on the if statement
SylveonDeko
SylveonDekoOP16mo ago
running it with ? still makes it stop
S-IERRA
S-IERRA16mo ago
not the assignment
SylveonDeko
SylveonDekoOP16mo ago
oh
S-IERRA
S-IERRA16mo ago
1s
SylveonDeko
SylveonDekoOP16mo ago
wait Thonk
S-IERRA
S-IERRA16mo ago
?
SylveonDeko
SylveonDekoOP16mo ago
nvm
S-IERRA
S-IERRA16mo ago
r u sure its failing at that point w/o debugger
SylveonDeko
SylveonDekoOP16mo ago
yes i can add console logs 🤷‍♂️
S-IERRA
S-IERRA16mo ago
yes, would be good i feel like they might have over ridden the is operator and its doing some more bs
SylveonDeko
SylveonDekoOP16mo ago
lets see
onefuture
onefuture16mo ago
Blud is discord support for FREE
SylveonDeko
SylveonDekoOP16mo ago
wat.
SylveonDeko
SylveonDekoOP16mo ago
this makes no fucking sense
S-IERRA
S-IERRA16mo ago
yh was right then its failing somewhere down the line
SylveonDeko
SylveonDekoOP16mo ago
but then
SylveonDeko
SylveonDekoOP16mo ago
this would have stopped it
SylveonDeko
SylveonDekoOP16mo ago
i put a debug marker there too
Patrick
Patrick16mo ago
!ban @1ftr trolling
SylveonDeko
SylveonDekoOP16mo ago
wat.
S-IERRA
S-IERRA16mo ago
try putting logs line by line tbf, then you ll haev a betetr idea
SylveonDeko
SylveonDekoOP16mo ago
S-IERRA
S-IERRA16mo ago
ch wouldnt error thats just assignment its just null
SylveonDeko
SylveonDekoOP16mo ago
ofc it wouldnt but it would at least stop right?
S-IERRA
S-IERRA16mo ago
nah is just an empty assignment no reason to stop
SylveonDeko
SylveonDekoOP16mo ago
S-IERRA
S-IERRA16mo ago
press f11
SylveonDeko
SylveonDekoOP16mo ago
ok so it turns out im just a moron got it
S-IERRA
S-IERRA16mo ago
prolly this
SylveonDeko
SylveonDekoOP16mo ago
weird
S-IERRA
S-IERRA16mo ago
idk what this method does but could be this?
S-IERRA
S-IERRA16mo ago
but ye it ssomewhere there
SylveonDeko
SylveonDekoOP16mo ago
heard this and have been using it ever since: To avoid these problems, we can use ConfigureAwait(false) to tell await not to capture and resume on the current context, but instead resume on any available thread. This can improve performance, scalability and avoid deadlocks in some scenarios
Angius
Angius16mo ago
It's only really useful in old .NET Framework and in libraries
SylveonDeko
SylveonDekoOP16mo ago
ah got it
Angius
Angius16mo ago
I don't think it does anything useful since Core Try yeeting it all and see what happens
SylveonDeko
SylveonDekoOP16mo ago
trying
SylveonDeko
SylveonDekoOP16mo ago
yknow im a massive moron sometimes
SylveonDeko
SylveonDekoOP16mo ago
ok yeah it doesnt fail there
S-IERRA
S-IERRA16mo ago
so far so good btw just for future reference try doing what i do
SylveonDeko
SylveonDekoOP16mo ago
?
S-IERRA
S-IERRA16mo ago
public async Task<GenericResponse<NumixListing>> ModifyListing(Guid listingId, ModifyListingRequest request)
{
_logger.Information($"ListingImplementation:ModifyListing - Start (ListingId: {listingId})");

await using var context = ContextFactory.CreateDbContext();
if (await context.Listings.FirstOrDefaultAsync() is not { } numixListing)
{
_logger.Information($"ListingImplementation:ModifyListing - Listing not found (ListingId: {listingId})");
return new GenericResponse<NumixListing>(null, "Listing not found");
}
public async Task<GenericResponse<NumixListing>> ModifyListing(Guid listingId, ModifyListingRequest request)
{
_logger.Information($"ListingImplementation:ModifyListing - Start (ListingId: {listingId})");

await using var context = ContextFactory.CreateDbContext();
if (await context.Listings.FirstOrDefaultAsync() is not { } numixListing)
{
_logger.Information($"ListingImplementation:ModifyListing - Listing not found (ListingId: {listingId})");
return new GenericResponse<NumixListing>(null, "Listing not found");
}
sec i ll give context
[HttpPatch("{listingId:guid}")]
public async Task<IActionResult> ModifyListing(Guid listingId, ModifyListingRequest request)
{
GenericResponse<NumixListing> genericResponse = await _listingService.ModifyListing(listingId, request);
if (genericResponse.ErrorMessage is not null)
return Problem(genericResponse.ErrorMessage);

await _cachedListingService.UpdateCache(genericResponse.Model!);

return Ok();
}
[HttpPatch("{listingId:guid}")]
public async Task<IActionResult> ModifyListing(Guid listingId, ModifyListingRequest request)
{
GenericResponse<NumixListing> genericResponse = await _listingService.ModifyListing(listingId, request);
if (genericResponse.ErrorMessage is not null)
return Problem(genericResponse.ErrorMessage);

await _cachedListingService.UpdateCache(genericResponse.Model!);

return Ok();
}
so when u have an error dont just do an empty return try to atleast log it makes ur life x1000 easier
SylveonDeko
SylveonDekoOP16mo ago
yeah also i just realized the dumb i did lel
S-IERRA
S-IERRA16mo ago
what was wrong
SylveonDeko
SylveonDekoOP16mo ago
before i fixed it, this was just checkking is null
SylveonDeko
SylveonDekoOP16mo ago
and of course, it was just eeveefacepalm see if that fixes it lel it did not, bug hunting time
SylveonDeko
SylveonDekoOP16mo ago
and fixed it
SylveonDeko
SylveonDekoOP16mo ago
kek thx guys for guiding me through my stupidity its been a Brainless day today
S-IERRA
S-IERRA16mo ago
nws nws happens currently im loosing my shit too over a ticket below you so
SylveonDeko
SylveonDekoOP16mo ago
lolol good luck
jcotton42
jcotton4216mo ago
it still does the same thing it doesn't use the active sync context to schedule the continuation for example, in a GUI app
// on UI thread
await Task.Delay(250);
// still on UI thread, b/c the sync context installed by the framework put us here
await Task.Delay(250).ConfigureAwait(false);
// no more sync context, default scheduler used
// we're now on the thread pool
// on UI thread
await Task.Delay(250);
// still on UI thread, b/c the sync context installed by the framework put us here
await Task.Delay(250).ConfigureAwait(false);
// no more sync context, default scheduler used
// we're now on the thread pool
@ZZZZZZZZZZZZZZZZZZZZZZZZZ in the case of a discord bot, you probably don't have a sync context, so it won't affect anything either way
Angius
Angius16mo ago
Didn't something change about it with Core?
jcotton42
jcotton4216mo ago
Stephen Toub - MSFT
.NET Blog
ConfigureAwait FAQ - .NET Blog
.NET added async/await to the languages and libraries over seven years ago. In that time, it’s caught on like wildfire, not only across the .NET ecosystem, but also being replicated in a myriad of other languages and frameworks. It’s also seen a ton of improvements in .NET,
jcotton42
jcotton4216mo ago
not how it works fundamentally
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server