Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pytz
- def toJSON(message, realtime=True):
- message_obj = {
- 'timestamp': pytz.utc.localize(message.timestamp),
- 'tts': message.tts,
- 'author': {
- 'name': message.author.name,
- 'id': message.author.id,
- 'discriminator': message.author.discriminator,
- 'avatar': message.author.avatar,
- 'bot': message.author.bot,
- 'avatar_url': message.author.avatar_url,
- 'mention': message.author.mention,
- 'display_name': message.author.display_name,
- 'created_at': pytz.utc.localize(message.author.created_at), # "Returns the user’s creation time in UTC."
- 'voice': {
- 'deaf': message.author.voice.deaf,
- 'mute': message.author.voice.mute,
- 'self_mute': message.author.voice.self_mute,
- 'self_deaf': message.author.voice.self_deaf
- },
- 'joined_at': pytz.utc.localize(message.author.joined_at),
- 'nick': message.author.nick,
- 'top_role': {
- 'id': message.author.top_role.id,
- 'name': message.author.top_role.name,
- 'position': message.author.top_role.position,
- 'mentionable': message.author.top_role.mentionable,
- 'created_at': pytz.utc.localize(message.author.top_role.created_at),
- 'mention': message.author.top_role.mention
- },
- },
- 'content': message.content,
- 'channel': {
- 'name': message.channel.name,
- 'id': message.channel.id,
- 'topic': message.channel.topic,
- 'position': message.channel.position,
- 'mention': message.channel.mention,
- 'created_at': pytz.utc.localize(message.channel.created_at) # "Returns the channel’s creation time in UTC."
- },
- 'server': {
- 'name': message.server.name,
- 'icon': message.server.icon,
- 'id': message.server.id,
- 'icon_url': message.server.icon_url,
- 'member_count': message.server.member_count,
- 'created_at': pytz.utc.localize(message.server.created_at) # "Returns the server’s creation time in UTC."
- },
- 'mention_everyone': message.mention_everyone,
- 'id': message.id,
- 'attachments': message.attachments,
- 'raw_mentions': message.raw_mentions,
- 'raw_channel_mentions': message.raw_channel_mentions,
- 'raw_role_mentions': message.raw_role_mentions
- }
- if realtime == False:
- message_obj['pinned'] = message.pinned
- message.reactions = [{'id':x.emoji.id,'count':x.count} for x in message.reactions]
- return message_obj
Add Comment
Please, Sign In to add comment