I’m developing a Discord bot using Python to enhance my programming skills, but I’m facing an error when I attempt to run it. This is the setup I’ve been using:
# main.py
import bot_module
if __name__ == '__main__':
bot_module.launch_bot()
# responses_module.py
import random
def process_message(msg) -> str:
cleaned_message = msg.lower()
if cleaned_message == "hi":
return "Hello!"
if cleaned_message == "roll":
return str(random.randint(1, 6))
if cleaned_message == "!help":
return "This command provides help."
# bot_module.py
import discord
import responses_module
async def send_reply(msg, user_input, private):
try:
reply = responses_module.process_message(user_input)
await msg.author.send(reply) if private else await msg.channel.send(reply)
except Exception as e:
print(e)
def launch_bot():
TOKEN = '################################################################'
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} is now online!')
@client.event
async def on_message(msg):
if msg.author == client.user:
return
user = str(msg.author)
user_input = str(msg.content)
channel = str(msg.channel)
if user_input[0] == "?":
user_input = user_input[1:]
await send_reply(msg, user_input, private=True)
else:
await send_reply(msg, user_input, private=False)
client.run(TOKEN)
When I execute this code, I receive:
Traceback (most recent call last):
File "main.py", line 4, in <module>
bot_module.launch_bot()
File "bot_module.py", line 12, in launch_bot
client = discord.Client()
TypeError: Client.__init__() missing 1 required keyword-only argument: 'intents'
I’ve rearranged the code but it hasn’t helped. What does this intents error signify, and how can I resolve it?