-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
-
I'm currently trying to make a chat bot users can message in dms:
async def send_response(self, message: MyMessage): """Send a response back to the Discord channel""" if not self.bot: return # Get the channel channel = self.bot.get_channel(int(message.channel)) # This returns `None` if channel: # Consequently. this fails await channel.send(message.content)
I've made extra sure that the CHANNEL_ID ( the one you can copy with RMB -> Copy Channel ID is exactly the same as the one that is being passed to that function. I also tried doing the same thing in a server channel... Which works perfectly fine.
Now I'm under the impression that I'm either doing something wrong or the get_channel function isn't working properly.
Beta Was this translation helpful? Give feedback.
All reactions
DMs are only available on a LRU cache of 128 channels because Discord does not actually recommend keeping track of these long term. This is documented and warned pretty sure. You can also just use Client.get_partial_messageable to avoid an API call if you know the channel ID is valid.
Replies: 1 comment 5 replies
-
Message.channel is already a channel. Use this?
Discord Channel objects don't support int casts in the way you're trying to use them. If you had used the message.channel.id attribute it would be fine, even then it's already an int.
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm writing a system that is not exclusively taking inputs from discord. For this matter I have to have some middle ground. The Message type is not an actual discord.Message but a type of my own.
In the context of that type, id is being stored as a string.
I've just now also tried to get the user instead of the channel because I saw an ancient issue about dm channels not having it's own channel_id and it instead being a user_id. But even that returns None:
image
I really want to avoid using a whole lot of methods that are exclusive to discord for the reason stated above.
Some more context:
@dataclass(slots=True) class MyMessage: channel_id: str direction: Literal["in", "out"] content: str author: str role: Literal["system", "assistant", "user"] response_time: float timestamp: float = time.time()
I surely could just "add" the methods to directly act upon the message but then it became exclusive to discord and I would have to do that for every single input.
Beta Was this translation helpful? Give feedback.
All reactions
-
After further debugging I looks like that bot.fetch_channel is working properly and returns the DMChannel as desired. However directly using the api undermines most of what discord.py is meant for.
Does this indicate an issue with the get_channel function?
Beta Was this translation helpful? Give feedback.
All reactions
-
DMs are only available on a LRU cache of 128 channels because Discord does not actually recommend keeping track of these long term. This is documented and warned pretty sure. You can also just use Client.get_partial_messageable to avoid an API call if you know the channel ID is valid.
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm very far away from 128 channels. However using a partial does indeed work.
Beta Was this translation helpful? Give feedback.
All reactions
-
You also don't get DM channels at all until someone sends a message there either.
Beta Was this translation helpful? Give feedback.