disnake.py Bot for tracking users

46 Views Asked by At

I tried to make a discord bot that tracks who logged in and out, but I failed. Please help me, thank you.

from disnake.ext import commands

intents = disnake.Intents.default() #
intents.presences = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
print('Бот готов к работе.')

@bot.event
async def on_member_update(before, after):
if before.status != disnake.Status.online and after.status == disnake.Status.online:
print(f'{after.name} зашел в сеть.')
elif before.status == disnake.Status.online and after.status !=:
print(f'{after.name} вышел из сети.')
disnake.Status.online
bot.run("TOKEN")```
1

There are 1 best solutions below

0
boez On

You need to enable the Intents.members intent in your code. Also go to the Developer Portal and the Bot section to enable the Members intent.

from disnake.ext import commands

intents = disnake.Intents.default()
intents.members = True
intents.presences = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
print('Бот готов к работе.')

@bot.event
async def on_member_update(before, after):
   if before.status != disnake.Status.online and after.status == disnake.Status.online:
      print(f'{after.name} зашел в сеть.')
   elif before.status == disnake.Status.online and after.status != disnake.Status.online:
      print(f'{after.name} вышел из сети.')

bot.run("TOKEN")