How Can I Transfer An Json File Into An Embed On Discord.py?
I tried this: @bot.command() @commands.has_any_role('KING') async def list(ctx): with open(r'F:\DiscordBot\PyCharm\Knastwärter\knastusers.json', 'r')as read_file: use
Solution 1:
I think you are not going to transfer json file itself, or your code may be seen like this:
@bot.command(name='file')asyncdefcmd_file(ctx):
await ctx.send(file=discord.File('./a.json'))
Your problem is how to transfer the information in the json file, so I think you need Embed.add_field
to achieve this:
@bot.command(name='list')asyncdefcmd_list(ctx):
withopen('./a.json', 'r') as read_file:
users = json.load(read_file)
embedlist = discord.Embed(title='Title', description='User List')
join = lambda x: '\n'.join(x)
embedlist.add_field(name='User Name', value=join(users.values()))
embedlist.add_field(name='User ID', value=join(users.keys()))
await ctx.send(embed=embedlist)
Note that list
is a built-in data type, you should avoid naming your function as list
. I suggest you put a prefix to your function name and using name
argument to bot.command
.
The result:
You can adjust to what you like, there are more detail in documentation of discord.py, including lots of methods to beautify your embed.
Post a Comment for "How Can I Transfer An Json File Into An Embed On Discord.py?"