Home > front end >  How to fix this Error in Discord.py on Heroku?
How to fix this Error in Discord.py on Heroku?

Time:04-21

I'm using Heroku as my server host of my Discord.py bot, but i am having a problem. the problem is:

2022-04-21T07:16:49.427897 00:00 heroku[worker.1]: State changed from crashed to
 starting
2022-04-21T07:16:57.165858 00:00 heroku[worker.1]: Starting process with command
 `python test.py`
2022-04-21T07:16:57.779154 00:00 heroku[worker.1]: State changed from starting t
o up
2022-04-21T07:16:58.220518 00:00 app[worker.1]: Traceback (most recent call last
):
2022-04-21T07:16:58.220539 00:00 app[worker.1]: File "test.py", line 4, in <modu
le>
2022-04-21T07:16:58.220609 00:00 app[worker.1]: client = discord.Client()
2022-04-21T07:16:58.220632 00:00 app[worker.1]: TypeError: __init__() missing 1
required keyword-only argument: 'intents'
2022-04-21T07:16:58.378966 00:00 heroku[worker.1]: Process exited with status 1
2022-04-21T07:16:58.431162 00:00 heroku[worker.1]: State changed from up to cras
hed

The main problem is the TypeError: __init__() missing 1 required keyword-only argument: 'intents' The requirements.txt and Procfile is all good. I have a feeling the culprit could be the symbol @ though still answer this, thanks.

However here is my discord.py code

import discord
from discord.ext import commands
token = '(Obviously the token is here)'
prefix = "."

bot = commands.Bot(command_prefix=prefix)

@bot.event
async def on_ready():
    print('Internal has connected to Discord!')
    await bot.change_presence(activity=discord.Game(name="Discord"))
    
@bot.command()
async def ping(ctx):
    await ctx.send(f'Pong! In {round(bot.latency * 1000)}ms')

@bot.command()
async def about(ctx):
    embed = discord.Embed(title='About me!', description=f'Im an Utility bot, that is coded under discord.py\n\n> Statistics\nLatency: `{round(bot.latency * 1000)}`ms', color=0xEE8700)
    await ctx.send(embed=embed)

@bot.command()
async def say(ctx, *, content:str):
    await ctx.send(content)

bot.run(token)

CodePudding user response:

A little disclaimer: Join the https://discord.com/invite/r3sSKJJ

How to change the code:

  1. Head over to the Discord Developer Portal and click on your application
  2. Head over to Botand find Privileged Gateway Intents. Tick whatever you need
  3. In your code, you then need to import them:
intents = discord.Intents.default() # or .all() if you ticked all, that is easier
intents.members = True # If you ticked the SERVER MEMBERS INTENT

bot = commands.Bot(command_prefix=".", intents=intents) # "Import" the intents

This should resolve your error.

  • Related