visit
Hey!
Navigate to the
Save the default settings for Public Bot (checked) and Require OAuth2 Code Grant (unchecked).
Congrats! Your bot has been created. It was easy, wasn't it?
This token is your bot's private password so don't share it with anybody and use a password manager if necessary.
Now choose the actions you want to be permitted for the bot. Our bot is going to mainly use text messages so we don't need a lot of permissions.
After selecting the appropriate permissions, click the 'Copy' button below the permissions. This way you'll copy a URL that is used to add the bot to a server.
Сlick “Authorize”. And you’re almost done!
To add the bot, your account needs to have "Manage Server" permissions allowed.
Our main goal here is to get data from Servers and analyze it. You can find more options here:
# Import Libraries
import discord
import asyncio
import pandas as pd
from aiohttp import ClientConnectorError
intents = discord.Intents.all()
client = discord.Client(intents=intents)
token = "YOUR_TOKEN"
@client.event
async def on_ready():
# Code to getting data
await client.close()
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(client.start(token))
except ClientConnectorError:
print("Discord connection error try again")
@client.event
async def on_ready():
channels_columns = ['channel_id', 'channel_name', 'server_name', 'server_id']
list_channels = []
for guild in client.guilds:
for channel in guild.text_channels:
try:
# two lines to check access to the channel
channelh = client.get_channel(channel.id)
# trying to get last 10 messages from a channel
messages = await channelh.history(limit=10).flatten()
to_append_ch = [channel.id, channel.name, guild.name, guild.id]
list_channels.append(to_append_ch)
except discord.Forbidden: # 403 Forbidden (error code: 50001): Missing Access
print(f'channel {channel.name} has no access')
continue
df_channels = pd.DataFrame(list_channels, columns=channels_columns)
print(df_channels)
await client.close()
channelh = client.get_channel(channel.id)
messages = await channelh.history(limit=10).flatten()
@client.event
async def on_ready():
channels_columns = ['channel_id', 'channel_name', 'server_name', 'server_id']
memders_columns = ['member_id', 'name', 'discriminator', 'joined_at',
'server_name', 'server_id']
list_channels = []
list_memders = []
for guild in client.guilds:
for channel in guild.text_channels:
try:
# two lines to check access to the channel
channelh = client.get_channel(channel.id)
# trying to get last 10 messages from a channel
messages = await channelh.history(limit=10).flatten()
to_append_ch = [channel.id, channel.name, guild.name, guild.id]
list_channels.append(to_append_ch)
except discord.Forbidden:
# 403 Forbidden (error code: 50001): Missing Access
print(f'channel {channel.name} has no access')
continue
for member in guild.members:
if not member.bot:
to_append_mem = [str(member.id), member.name,
member.discriminator, member.joined_at,
guild.name, guild.id]
list_memders.append(to_append_mem)
df_channels = pd.DataFrame(list_channels, columns=channels_columns)
print(df_channels)
df_memders = pd.DataFrame(list_memders, columns=memders_columns)
print(df_memders)
await client.close()
# Import Libraries
import discord
import asyncio
import pandas as pd
from aiohttp import ClientConnectorError
intents = discord.Intents.all()
client = discord.Client(intents=intents)
token = "YOUR_TOKEN"
@client.event
async def on_ready():
channels_columns = ['channel_id', 'channel_name', 'server_name', 'server_id']
memders_columns = ['member_id', 'name', 'discriminator', 'joined_at',
'server_name', 'server_id']
roles_columns = ['member_id', 'role_id', 'role_name', 'server_name', 'server_id']
list_channels = []
list_memders = []
list_roles = []
for guild in client.guilds:
for channel in guild.text_channels:
try:
# two lines to check access to the channel
channelh = client.get_channel(channel.id)
# trying to get last 10 messages from a channel
messages = await channelh.history(limit=10).flatten()
to_append_ch = [channel.id, channel.name, guild.name, guild.id]
list_channels.append(to_append_ch)
except discord.Forbidden:
# 403 Forbidden (error code: 50001): Missing Access
print(f'channel {channel.name} has no access')
continue
for member in guild.members:
if not member.bot:
to_append_mem = [str(member.id), member.name,
member.discriminator, member.joined_at,
guild.name, guild.id]
list_memders.append(to_append_mem)
us_member = guild.get_member(member.id)
for us_role in us_member.roles:
to_append_rol = [str(member.id), us_role.id,
us_role.name, guild.name, guild.id]
list_roles.append(to_append_rol)
df_channels = pd.DataFrame(list_channels, columns=channels_columns)
print(df_channels)
df_memders = pd.DataFrame(list_memders, columns=memders_columns)
print(df_memders)
df_roles = pd.DataFrame(list_roles, columns=roles_columns)
print(df_roles)
await client.close()
try:
loop = asyncio.get_event_loop()
loop.run_until_complete(client.start(token))
except ClientConnectorError:
print("Discord connection error try again")