Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.74k stars 462 forks source link

fix: category cooldown commands works in dms like other guild cooldowns #2603

Closed Revnoplex closed 1 month ago

Revnoplex commented 1 month ago

Summary

While testing certain cooldown types for my cooldown handler. I stumbled upon an error when using a command that had a category cooldown in DMs. Note that the other guild-like cooldown types such as BucketType.guild, BucketType.member and BucketType.role work fine in DMs. So it is reasonable to consider this an unintended error rather than intentional and should be fixed. The error was caused by returning the bucket id using (msg.channel.category or msg.channel).id which can result in an error when it tries to access the category attribute when the channel is not a GuildChannel such as a PrivateChannel which doesn't have a category attribute so it results in a AttributeError. By using (msg.channel.category if isinstance(msg.channel, discord.abc.GuildChannel) else msg.channel).id (a GuildChannel always has a category attribute), it won't try to access the attribute when it can't.

Information

Checklist

Revnoplex commented 1 month ago

no, wait it undid it, actually it merged it weirdly