Hi I have a Discord Bot set up and I have a Flask application running as well.
Is there anyway to get data of my discord server using something like the Discord API or Webhook?
Hi I have a Discord Bot set up and I have a Flask application running as well.
Is there anyway to get data of my discord server using something like the Discord API or Webhook?
For users, you have guild.members
Further, you can iterate over it and get their name and discriminator
You can do a command that gets you all the members and then you can get their length and send it to the flask application.
@client.command()
async def get_members(ctx):
await ctx.message.delete()
#This will get you all the members in your server
for user in list(ctx.guild.members):
print(user)
#You can do whatever you want here
As far as I have seen, the only convenient way of passing your bot info to a website is to have an instance of a bot running simultaneously (You could, of course, also make native API calls, but I wouldn't recommend that). So as soon as you start your flask application, you would also have to initialize an instance of your bot.
Your bot, by default, fetches certain information on initialization, such as the servers it's on. You should be able to present that information then to your website.
You can also use the client.get_... methods to gain additional information.
So, if you flask app needs certain information, you could initialize your client, create functions like
def get_guild_names():
return [guild.name for guild in client.guilds]
and then call them from your flask application.