I want to append a total number of message send by a user in a channel into a json file , it should look something like this
'name' : 'xx',
'channel' : 123456789,
'total_no_of_messages' : 1234
I'm currently using this code to get channel and user details and adding it into a dictionary , but I don't know how to dump it into a json file
@client.event
async def on_ready():
channels = []
users = []
data = {}
for i in dct_channels.values():
for j in i:
channels.append(j)
for j in dct_memb.values():
for i in j:
users.append(i)
messages = []
for j in channels:
channel = client.get_channel(j)
if isinstance(channel, discord.TextChannel):
async for message in channel.history(limit=None):
for i in users:
user = client.get_user(i)
if message.author == user:
messages.append(message.content)
data.setdefault(f'{user , channel}', [])
data[f'{user,channel}'].append(len(messages))
print(data)