我正在使用 Heroku 作為我的 Discord.py 機器人的服務器主機,但我遇到了問題。問題是:
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
主要問題是TypeError: __init__() missing 1 required keyword-only argument: 'intents'并且一切requirements.txt都Procfile很好。我有一種感覺,罪魁禍首可能是象征@,但仍然回答這個問題,謝謝。
然而,這是我的 discord.pycode
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)
uj5u.com熱心網友回復:
一點免責宣告:加入
如何更改代碼:
- 前往Discord 開發者門戶并單擊您的應用程式
- 前往
Bot并找到Privileged Gateway Intents. 勾選你需要的任何東西 - 在您的代碼中,您需要匯入它們:
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
這應該可以解決您的錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/460363.html
