❔ Im gonna lose my fucking mind over this

148 Replies
S-IERRA
S-IERRA2y ago
whats wrong
SylveonDeko
SylveonDekoOP2y ago
that^
Angius
Angius2y ago
what
SylveonDeko
SylveonDekoOP2y ago
channel is not null but it returns prematurely but doesnt touch the actual return;
S-IERRA
S-IERRA2y ago
ur on ridewr?
SylveonDeko
SylveonDekoOP2y ago
correct
S-IERRA
S-IERRA2y ago
S-IERRA
S-IERRA2y ago
igh sick run w debugger and hover over the variable for me
SylveonDeko
SylveonDekoOP2y ago
its on lol
Angius
Angius2y ago
It's really hard to say what's wrong by just seeing 3 lines of code
S-IERRA
S-IERRA2y ago
can u hover over the var and show me what the values are
SylveonDeko
SylveonDekoOP2y ago
now, why do you think im saying its not null?
onefuture
onefuture2y ago
@new FuckPremiumBots() have you considered this
onefuture
onefuture2y 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-IERRA2y ago
f10
blinkbat
blinkbat2y ago
...why
Jimmacle
Jimmacle2y ago
this is not a helpful suggestion
SylveonDeko
SylveonDekoOP2y ago
wat.
S-IERRA
S-IERRA2y ago
see what it says ah ok
onefuture
onefuture2y ago
im guessing you are using discord.net right?
SylveonDeko
SylveonDekoOP2y ago
yes
onefuture
onefuture2y 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-IERRA2y ago
@new FuckPremiumBots() it could be that its failing to fetch the channel
onefuture
onefuture2y ago
heres a better alternative
Jimmacle
Jimmacle2y ago
are you trying to speedrun a ban?
SylveonDeko
SylveonDekoOP2y ago
how
S-IERRA
S-IERRA2y ago
S-IERRA
S-IERRA2y ago
here
SylveonDeko
SylveonDekoOP2y ago
im literally giving it the channel
S-IERRA
S-IERRA2y ago
yes but discord is weird had the same issue in py
SylveonDeko
SylveonDekoOP2y 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-IERRA2y ago
uhm can you try to run w/o debugger
SylveonDeko
SylveonDekoOP2y ago
the method thats calling it ok
blinkbat
blinkbat2y ago
oh finally a whole block of code
onefuture
onefuture2y ago
almost blinded myself looking at that
SylveonDeko
SylveonDekoOP2y ago
you aint gonna have no future if you keep being an attention seeking brat let alone 1future
S-IERRA
S-IERRA2y ago
just ignore
blinkbat
blinkbat2y ago
that code block doesn't look like the bug you experienced
SylveonDeko
SylveonDekoOP2y ago
ik, just had to get that out
onefuture
onefuture2y ago
ask chat gpt to optimize it
SylveonDeko
SylveonDekoOP2y 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
blinkbat2y ago
it could be hitting any of those returns
SylveonDeko
SylveonDekoOP2y ago
onefuture
onefuture2y 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
SylveonDekoOP2y ago
where for some reason channel was null
S-IERRA
S-IERRA2y ago
yes like i said
SylveonDeko
SylveonDekoOP2y ago
but that was only socket
S-IERRA
S-IERRA2y ago
it could be failing to fetch it as a fallback value
SylveonDeko
SylveonDekoOP2y ago
rest returns it fine
S-IERRA
S-IERRA2y ago
missing intent most likley
SylveonDeko
SylveonDekoOP2y ago
nope
S-IERRA
S-IERRA2y ago
weird
SylveonDeko
SylveonDekoOP2y ago
all intents on and configured
blinkbat
blinkbat2y ago
debug after that line see the value of channel
SylveonDeko
SylveonDekoOP2y ago
that code is long changed, channel is null becausse its null for some reason despite not being null in the calling method
blinkbat
blinkbat2y ago
why would you send old code
SylveonDeko
SylveonDekoOP2y ago
^
blinkbat
blinkbat2y ago
do you have a bug or not
SylveonDeko
SylveonDekoOP2y ago
yes
onefuture
onefuture2y 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
blinkbat2y ago
can you like stop maybe
onefuture
onefuture2y ago
...
Jimmacle
Jimmacle2y ago
just report and move on
onefuture
onefuture2y ago
im sending better code
SylveonDeko
SylveonDekoOP2y ago
channel is NOT null here so im confused af
S-IERRA
S-IERRA2y ago
@new FuckPremiumBots() im thinking it could be race contition related
SylveonDeko
SylveonDekoOP2y ago
oh boy thats fun
S-IERRA
S-IERRA2y ago
because if ur doing an async operation then its failing to fetch it in time then its ffailing on the if statement
SylveonDeko
SylveonDekoOP2y ago
definitely possible
S-IERRA
S-IERRA2y ago
because when you run it thru debugger it worked
SylveonDeko
SylveonDekoOP2y ago
lovely what could the race condition be tho
S-IERRA
S-IERRA2y ago
it wouldnt make sense tho cuz ur awaiting it
SylveonDeko
SylveonDekoOP2y ago
the async methods dont run since i give the values and they arent null
S-IERRA
S-IERRA2y ago
S-IERRA
S-IERRA2y ago
on debugger can u check
SylveonDeko
SylveonDekoOP2y ago
yeah
S-IERRA
S-IERRA2y ago
wait u did nvm
SylveonDeko
SylveonDekoOP2y ago
thats why channel isnt null im losing braincells trying to figure this out lmao
S-IERRA
S-IERRA2y ago
write ITextChannel?
S-IERRA
S-IERRA2y ago
even with IGuild
SylveonDeko
SylveonDekoOP2y ago
yes
S-IERRA
S-IERRA2y ago
im pretty sure thats the issue
SylveonDeko
SylveonDekoOP2y ago
why would that be an issue Thonk
S-IERRA
S-IERRA2y ago
isnt nullable and over c# 8 thats an issue
SylveonDeko
SylveonDekoOP2y ago
it is Thonk you mean put a ?
S-IERRA
S-IERRA2y ago
yes ITextChannel? inputChannel = null
SylveonDeko
SylveonDekoOP2y ago
in which case it shouldnt matter because i do the same with my commands and it doesnt have an issue
S-IERRA
S-IERRA2y ago
just try it see what it does
SylveonDeko
SylveonDekoOP2y ago
alr
S-IERRA
S-IERRA2y 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
SylveonDekoOP2y ago
SylveonDeko
SylveonDekoOP2y ago
same with inputchannel
S-IERRA
S-IERRA2y ago
ignore that then but ud put that on the if statement
SylveonDeko
SylveonDekoOP2y ago
running it with ? still makes it stop
S-IERRA
S-IERRA2y ago
not the assignment
SylveonDeko
SylveonDekoOP2y ago
oh
S-IERRA
S-IERRA2y ago
1s
SylveonDeko
SylveonDekoOP2y ago
wait Thonk
S-IERRA
S-IERRA2y ago
?
SylveonDeko
SylveonDekoOP2y ago
nvm
S-IERRA
S-IERRA2y ago
r u sure its failing at that point w/o debugger
SylveonDeko
SylveonDekoOP2y ago
yes i can add console logs 🤷‍♂️
S-IERRA
S-IERRA2y ago
yes, would be good i feel like they might have over ridden the is operator and its doing some more bs
SylveonDeko
SylveonDekoOP2y ago
lets see
onefuture
onefuture2y ago
Blud is discord support for FREE
SylveonDeko
SylveonDekoOP2y ago
wat.
SylveonDeko
SylveonDekoOP2y ago
this makes no fucking sense
S-IERRA
S-IERRA2y ago
yh was right then its failing somewhere down the line
SylveonDeko
SylveonDekoOP2y ago
but then
SylveonDeko
SylveonDekoOP2y ago
this would have stopped it
SylveonDeko
SylveonDekoOP2y ago
i put a debug marker there too
Patrick
Patrick2y ago
!ban @1ftr trolling
SylveonDeko
SylveonDekoOP2y ago
wat.
S-IERRA
S-IERRA2y ago
try putting logs line by line tbf, then you ll haev a betetr idea
SylveonDeko
SylveonDekoOP2y ago
S-IERRA
S-IERRA2y ago
ch wouldnt error thats just assignment its just null
SylveonDeko
SylveonDekoOP2y ago
ofc it wouldnt but it would at least stop right?
S-IERRA
S-IERRA2y ago
nah is just an empty assignment no reason to stop
SylveonDeko
SylveonDekoOP2y ago
S-IERRA
S-IERRA2y ago
press f11
SylveonDeko
SylveonDekoOP2y ago
ok so it turns out im just a moron got it
S-IERRA
S-IERRA2y ago
prolly this
SylveonDeko
SylveonDekoOP2y ago
weird
S-IERRA
S-IERRA2y ago
idk what this method does but could be this?
S-IERRA
S-IERRA2y ago
but ye it ssomewhere there
SylveonDeko
SylveonDekoOP2y 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
Angius2y ago
It's only really useful in old .NET Framework and in libraries
SylveonDeko
SylveonDekoOP2y ago
ah got it
Angius
Angius2y ago
I don't think it does anything useful since Core Try yeeting it all and see what happens
SylveonDeko
SylveonDekoOP2y ago
trying
SylveonDeko
SylveonDekoOP2y ago
yknow im a massive moron sometimes
SylveonDeko
SylveonDekoOP2y ago
ok yeah it doesnt fail there
S-IERRA
S-IERRA2y ago
so far so good btw just for future reference try doing what i do
SylveonDeko
SylveonDekoOP2y ago
?
S-IERRA
S-IERRA2y 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
SylveonDekoOP2y ago
yeah also i just realized the dumb i did lel
S-IERRA
S-IERRA2y ago
what was wrong
SylveonDeko
SylveonDekoOP2y ago
before i fixed it, this was just checkking is null
SylveonDeko
SylveonDekoOP2y ago
and of course, it was just eeveefacepalm see if that fixes it lel it did not, bug hunting time
SylveonDeko
SylveonDekoOP2y ago
and fixed it
SylveonDeko
SylveonDekoOP2y ago
kek thx guys for guiding me through my stupidity its been a Brainless day today
S-IERRA
S-IERRA2y ago
nws nws happens currently im loosing my shit too over a ticket below you so
SylveonDeko
SylveonDekoOP2y ago
lolol good luck
jcotton42
jcotton422y 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
Angius2y ago
Didn't something change about it with Core?
jcotton42
jcotton422y 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
jcotton422y ago
not how it works fundamentally
Accord
Accord17mo 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.

Did you find this page helpful?