I am currently building a Discord bot to enhance my Python skills, but I’m facing challenges when trying to initiate the bot. Here’s my code layout:
# main.py
import bot
if __name__ == '__main__':
bot.run_discord_bot()
# responses.py
import random
def handle_response(message) -> str:
processed_message = message.lower()
if processed_message == "Greetings":
return "Hello!"
if processed_message == "Roll dice":
return str(random.randint(1, 6))
if processed_message == "!helpinfo":
return "Here is a help message for users."
# bot.py
import discord
import responses
async def send_message(msg, user_msg, private):
try:
reply = responses.handle_response(user_msg)
await msg.author.send(reply) if private else await msg.channel.send(reply)
except Exception as e:
print(e)
def run_discord_bot():
TOKEN = '################################################################'
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} is successfully running!')
@client.event
async def on_message(msg):
if msg.author == client.user:
return
username = str(msg.author)
user_message = str(msg.content)
channel = str(msg.channel)
if user_message[0] == "?":
user_message = user_message[1:]
await send_message(msg, user_message, private=True)
else:
await send_message(msg, user_message, private=False)
client.run(TOKEN)
Upon executing this in VS Code, I receive the following error:
Traceback (most recent call last):
File "c:\Users\#####\Desktop\Python Scripts\Discord_Bot\main.py", line 4, in <module>
bot.run_discord_bot()
File "c:\Users\#####\Desktop\Python Scripts\Discord_Bot\bot.py", line 13, in run_discord_bot
client = discord.Client()
TypeError: Client.__init__() missing 1 required keyword-only argument: 'intents'
I’m unsure of what this intents argument refers to. I’ve attempted to rearrange the code but haven’t had any success. Any guidance on resolving this would be greatly appreciated.