11from random import choice
22
3- from discord import TextChannel
3+ import discord
44
55from ..interface import Adapter
6- from ..utils import escape_content
6+ from ..utils import DPY2 , escape_content
77from ..verb import Verb
88
99__all__ = (
@@ -19,10 +19,11 @@ class AttributeAdapter(Adapter):
1919
2020 def __init__ (self , base ):
2121 self .object = base
22+ created_at = getattr (base , "created_at" , None ) or discord .utils .snowflake_time (base .id )
2223 self ._attributes = {
2324 "id" : base .id ,
24- "created_at" : base . created_at ,
25- "timestamp" : int (base . created_at .timestamp ()),
25+ "created_at" : created_at ,
26+ "timestamp" : int (created_at .timestamp ()),
2627 "name" : getattr (base , "name" , str (base )),
2728 }
2829 self ._methods = {}
@@ -107,18 +108,19 @@ class MemberAdapter(AttributeAdapter):
107108 """
108109
109110 def update_attributes (self ):
111+ avatar_url = self .object .display_avatar .url if DPY2 else self .object .avatar_url
110112 joined_at = getattr (self .object , "joined_at" , self .object .created_at )
111113 additional_attributes = {
112114 "color" : self .object .color ,
113115 "colour" : self .object .color ,
114116 "nick" : self .object .display_name ,
115- "avatar" : (self . object . avatar_url , False ),
117+ "avatar" : (avatar_url , False ),
116118 "discriminator" : self .object .discriminator ,
117119 "joined_at" : joined_at ,
118120 "joinstamp" : int (joined_at .timestamp ()),
119121 "mention" : self .object .mention ,
120122 "bot" : self .object .bot ,
121- "top_role" : getattr (self .object , "top_role" , None ),
123+ "top_role" : getattr (self .object , "top_role" , "" ),
122124 }
123125 if roleids := getattr (self .object , "_roles" , None ):
124126 additional_attributes ["roleids" ] = " " .join (str (r ) for r in roleids )
@@ -156,11 +158,11 @@ class ChannelAdapter(AttributeAdapter):
156158 """
157159
158160 def update_attributes (self ):
159- if isinstance (self .object , TextChannel ):
161+ if isinstance (self .object , discord . TextChannel ):
160162 additional_attributes = {
161163 "nsfw" : self .object .nsfw ,
162164 "mention" : self .object .mention ,
163- "topic" : self .object .topic or None ,
165+ "topic" : self .object .topic or "" ,
164166 }
165167 self ._attributes .update (additional_attributes )
166168
@@ -213,8 +215,9 @@ def update_attributes(self):
213215 else :
214216 humans += 1
215217 member_count = guild .member_count
218+ icon_url = getattr (guild .icon , "url" , "" ) if DPY2 else guild .icon_url
216219 additional_attributes = {
217- "icon" : (guild . icon_url , False ),
220+ "icon" : (icon_url , False ),
218221 "member_count" : member_count ,
219222 "members" : member_count ,
220223 "bots" : bots ,
0 commit comments