For the users and channel counter, you would use the len() function to count how many there are. If you don't have the members intent enabled, you can also use ctx.guild.member_count.
# Using len()...
embed.add_field(name="Users:", value=ctx.guild.member_count, inline=False)
embed.add_field(name="Channels:", value=len(ctx.guild.channels), inline=False)
For messages however, you will need to use a database or global variable and manually increase the entry each time a message is sent. A global variable is much simpler to use than a database, however it will be flushed whenever the script ends or is restarted.
On a side note, if you want to use a database anyway, I recommend you check out dataset.
# Using a global variable (dictionary)
# Somewhere in your code...
messagecounts = {}
...
@bot.event
async def on_message(message):
if message.guild.id not in messagecounts.keys(): # Make sure there's already an entry... If not, add one!
messagecounts[message.guild.id] = 0
messagecounts[message.guild.id] += 1 # Sets the new count to 1 greater than the original.
Then, to retrieve this amount, you would add the dictionary entry.
Final Code:
# Somewhere above the command...
messagecounts = {}
@bot.command()
async def serverstats(ctx):
embed=discord.Embed(title=f"Statystyki serwera {ctx.guild.name}")
embed.add_field(name="Users:", value=ctx.guild.member_count, inline=False)
embed.add_field(name="Channels:", value=len(ctx.guild.channels), inline=False)
embed.add_field(name="Messages sent:", value=messagecounts[ctx.guild.id], inline=False)
await ctx.send(embed=embed)
@bot.event
async def on_message(message):
if message.guild.id not in messagecounts.keys():
messagecounts[message.guild.id] = 0
messagecounts[message.guild.id] += 1