You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the message trying to be converted is found, return directly
Otherwise, try to resolve the channel from the bot's cache.
If the channel isn't found, throw a ChannelNotFound exception
asyncdefconvert(self, ctx: Context[BotT], argument: str) ->discord.Message:
guild_id, message_id, channel_id=PartialMessageConverter._get_id_matches(ctx, argument)
message=ctx.bot._connection._get_message(message_id)
ifmessage:
returnmessagechannel=PartialMessageConverter._resolve_channel(ctx, guild_id, channel_id)
ifnotchannelornotisinstance(channel, discord.abc.Messageable):
raiseChannelNotFound(channel_id)
try:
returnawaitchannel.fetch_message(message_id)
exceptdiscord.NotFound:
raiseMessageNotFound(argument)
exceptdiscord.Forbidden:
raiseChannelNotReadable(channel) # type: ignore # type-checker thinks channel could be a DMChannel at this point
The problem here is that it tries to fetch the message if not found, but not the channel, which results in never being able to convert the message.
The Ideal Solution
Ideal solution would be to try to fetch the channel if it's not in cache, then (maybe) cache it again for future usages.
Which would result in something like
asyncdefconvert(self, ctx: Context[BotT], argument: str) ->discord.Message:
guild_id, message_id, channel_id=PartialMessageConverter._get_id_matches(ctx, argument)
message=ctx.bot._connection._get_message(message_id)
ifmessage:
returnmessagechannel=PartialMessageConverter._resolve_channel(ctx, guild_id, channel_id) orbot.fetch_channel(channel_id)
ifnotchannelornotisinstance(channel, discord.abc.Messageable):
raiseChannelNotFound(channel_id)
try:
returnawaitchannel.fetch_message(message_id)
exceptdiscord.NotFound:
raiseMessageNotFound(argument)
exceptdiscord.Forbidden:
raiseChannelNotReadable(channel) # type: ignore # type-checker thinks channel could be a DMChannel at this point
The Current Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered:
It's not this way on purpose so you don't get bombarded with (another) bogus 400 requests when someone crafts either a garbage URL with an obviously wrong ID or a message ID you can't read to begin with. This change would cause the invalid requests on the worst case to go from one 400 to two.
There is a PartialMessageable type now that could be used but it'd need some work in order to make ChannelNotFound viable.
It's not this way on purpose so you don't get bombarded with (another) bogus 400 requests when someone crafts either a garbage URL with an obviously wrong ID or a message ID you can't read to begin with. This change would cause the invalid requests on the worst case to go from one 400 to two.
There is a PartialMessageable type now that could be used but it'd need some work in order to make ChannelNotFound viable.
Hum, I see.
But leveraging a PartialMessage wouldn't really solve the issue in the MessageConverter, or am I missing something ?
I guess this would need to be done client-side once, then that can be cached along with the rest to avoid recurrent requests.
Summary
Fetch channel upon message converion
What is the feature request for?
discord.ext.commands
The Problem
Currently, here's how the MessageConverter works
If the message trying to be converted is found, return directly
Otherwise, try to resolve the channel from the bot's cache.
If the channel isn't found, throw a
ChannelNotFound
exceptionThe problem here is that it tries to fetch the message if not found, but not the channel, which results in never being able to convert the message.
The Ideal Solution
Ideal solution would be to try to
fetch
the channel if it's not in cache, then (maybe) cache it again for future usages.Which would result in something like
The Current Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: