I just started learning how to build a discord bot from real python. I wrote my code as instructed. Here it is:
# bot.py
import os
import random
import discord
client = discord.Client(intents=discord.Intents.default())
@client.event
async def on_ready():
print(f'{client.user.name} has connected to Discord!')
@client.event
async def on_member_join(member):
await member.create_dm()
await member.dm_channel.send(
f'Hi {member.name}, welcome to my Discord server!'
)
@client.event
async def on_message(message):
if message.author == client.user:
return
brooklyn_99_quotes = [
'I\'m the human form of the emoji.',
'Bingpot!',
(
'Cool. Cool cool cool cool cool cool cool, '
'no doubt no doubt no doubt no doubt.'
),
]
if message.content == '99!':
response = random.choice(brooklyn_99_quotes)
await message.channel.send(response)
client.run('don't u dare see my token')
#I am creating the file locally that's why I didn't use the .env file
I ran this code and this was the output:
(bot) D:\Programming\python\discord>python bot.py
[2022-09-17 14:34:29] [INFO ] discord.client: logging in using static token
[2022-09-17 14:34:31] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: dfdc75d74ccf9705dc5e71a2fccdbc5e).
Pybot has connected to Discord!
But the main problem here is that whenever I use my secondary ACC. to join the server or send 99! to the server the bot never responds. Please help.