JonnyPtn / zomboi

A discord bot for project zomboid multiplayer servers
49 stars 32 forks source link

Needs updates for discord.py 2.0 compatibility #50

Closed newplayerkkkjj closed 1 year ago

newplayerkkkjj commented 2 years ago

Can anyone help me and tell me what i have done wrong? Ty :D https://prnt.sc/zqN_UPfO1me1

Grim-reap3r commented 2 years ago

Hello,

looks like something is missing in " requirements.txt" because when I install a different bot this one start working too.

requirements.txt from another bot. Try to paste this into and then run pip3 install -r requirements.txt

aiofiles==0.8.0 aiohttp==3.8.1 aiosignal==1.2.0 anyio==3.5.0 async-timeout==4.0.2 asyncio==3.4.3 attrs==21.4.0 certifi==2021.10.8 charset-normalizer==2.0.10 colorama==0.4.4 DateTime==4.3 frozenlist==1.3.0 h11==0.12.0 httpcore==0.14.5 httpx==0.21.3 idna==3.3 multidict==6.0.2 nextcord==2.0.0b3 protobuf==3.19.3 pytz==2021.3 rfc3986==1.5.0 sniffio==1.2.0 yarl==1.7.2 zope.interface==5.4.0 python-dotenv==0.19.2 numpy==1.22.3

run and let me know. If you get an error msg like that...

https://prnt.sc/sQ42SMgM5PJl

open/edit file zomboi.py go to line 32 and change

from zomboi = commands.bot.Bot("!", intents=intents) to zomboi = commands.Bot("!", intents=intents)

Work for me on ubuntu 20.04 and 22.04

JonnyPtn can u please check that?

Thx

petegilb commented 1 year ago

yeah some dependency probably updated upstream

newplayerkkkjj commented 1 year ago

No, unfortunately it didn't solve the problem for me. This "ERROR discord.client Ignoring exception in on_ready .......client.py LINE 409, zomboi.py LINE 71 (in on_ready), perks.py LINE 16 (initself.loadHistory())..." keeps showing up. Has anyone found anything else that could be causing this?

JonnyPtn commented 1 year ago

Yeah seems discord.py has updated to version 2 which isn't compatible with zomboi - If you install discord version 1.x it should work, although we should probably look to update to version 2 or at least specify the version in the requirements file

ref: https://discordpy.readthedocs.io/en/stable/migrating.html

Alcatraz1337 commented 1 year ago

i have tried using discord==1.7.3, but i still get the same error when starting the zomboi.py.

i am using the requirements.txt provided by this repo, not from Grim-reap3r tho...

any ideas?

the error is below

python zomboi.py
2022-09-07 17:59:11 WARNING  discord.ext.commands.bot Privileged message content intent is missing, commands may not work as expected.
2022-09-07 17:59:11 INFO     discord.client logging in using static token
2022-09-07 17:59:11 INFO     discord.gateway Shard ID None has connected to Gateway (Session ID: 979bda99d8d91bf9a163d4e41eeef8b1).
2022-09-07 17:59:13,838:INFO:zomboi: We have logged in as servertest#2868
2022-09-07 17:59:13,839:INFO:zomboi: channel connected
2022-09-07 17:59:13,839:INFO:zomboi: Loading user history...
2022-09-07 17:59:13,847:INFO:zomboi: User history loaded
zomboi.py:69: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
  zomboi.add_cog(UserHandler(zomboi, logPath))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
zomboi.py:70: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
  zomboi.add_cog(ChatHandler(zomboi, logPath))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2022-09-07 17:59:13,848:INFO:zomboi: Loading Perk history...
2022-09-07 17:59:13 ERROR    discord.client Ignoring exception in on_ready
Traceback (most recent call last):
  File "/home/pzuser/.local/lib/python3.8/site-packages/discord/client.py", line 409, in _run_event
    await coro(*args, **kwargs)
  File "zomboi.py", line 71, in on_ready
    zomboi.add_cog(PerkHandler(zomboi, logPath))
  File "/home/pzuser/Zomboi/perks.py", line 16, in __init__
    self.loadHistory()
  File "/home/pzuser/Zomboi/perks.py", line 57, in loadHistory
    self.handleLog(*self.splitLine(line))
  File "/home/pzuser/Zomboi/perks.py", line 69, in handleLog
    user = userHandler.getUser(name)
AttributeError: 'NoneType' object has no attribute 'getUser'
JonnyPtn commented 1 year ago

Yeah that error is still from discord 2 - you may need to uninstall it then reinstall the older version

Alcatraz1337 commented 1 year ago

Hi, Jonny,

Thx for your reply. The error is fixed! But the message not forwarding to discord or discord message not relay to server problem still exists. Any idea?

And, it would be great to have 'Discord Bot setup guide in the readme.md file' don't you think? Cuz i guess the problem may be caused by wrong discord bot permission settings??

Cheers for your work~

afronob commented 1 year ago

Hi, thanks for your work guys. Still got the error even with discord downgrade to 1.7.3.

Any clue ?

@Alcatraz1337 how did you solve the problem?

Installing collected packages: discord
  Attempting uninstall: discord
    Found existing installation: discord 2.0.0
    Uninstalling discord-2.0.0:
      Successfully uninstalled discord-2.0.0
Successfully installed discord-1.7.3
pzserver@pzserver:~/zomboi$ python zomboi.py
2022-09-28 17:45:17 WARNING  discord.ext.commands.bot Privileged message content intent is missing, commands may not work as expected.
2022-09-28 17:45:17 INFO     discord.client logging in using static token
2022-09-28 17:45:18 INFO     discord.gateway Shard ID None has connected to Gateway (Session ID: ec4cd663bb48e8d36f1af2d00646c33f).
2022-09-28 17:45:20,350:INFO:zomboi: We have logged in as Spiffo#8817
2022-09-28 17:45:20,350:INFO:zomboi: channel connected
2022-09-28 17:45:20,351:INFO:zomboi: Loading user history...
2022-09-28 17:45:20,363:INFO:zomboi: User history loaded
/home/pzserver/zomboi/zomboi.py:69: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
  zomboi.add_cog(UserHandler(zomboi, logPath))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
/home/pzserver/zomboi/zomboi.py:70: RuntimeWarning: coroutine 'BotBase.add_cog' was never awaited
  zomboi.add_cog(ChatHandler(zomboi, logPath))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2022-09-28 17:45:20,364:INFO:zomboi: Loading Perk history...
2022-09-28 17:45:20 ERROR    discord.client Ignoring exception in on_ready
Traceback (most recent call last):
  File "/home/pzserver/.local/lib/python3.10/site-packages/discord/client.py", line 409, in _run_event
    await coro(*args, **kwargs)
  File "/home/pzserver/zomboi/zomboi.py", line 71, in on_ready
    zomboi.add_cog(PerkHandler(zomboi, logPath))
  File "/home/pzserver/zomboi/perks.py", line 16, in __init__
    self.loadHistory()
  File "/home/pzserver/zomboi/perks.py", line 57, in loadHistory
    self.handleLog(*self.splitLine(line))
  File "/home/pzserver/zomboi/perks.py", line 69, in handleLog
    user = userHandler.getUser(name)
AttributeError: 'NoneType' object has no attribute 'getUser'
JonnyPtn commented 1 year ago

based on that output you're still using version 2.0

realgdubz commented 1 year ago

Been having the same problem for a month hopefully this is fixed

Alcatraz1337 commented 1 year ago

Hi @afronob , sorry for the late reply. I uninstall discord manually and specified the version==1.7.3 in the requirements.txt file. Also I use the python ver. 3.8 don't know if this would help.

afronob commented 1 year ago

@JonnyPtn based on that output :

Installing collected packages: discord
  Attempting uninstall: discord
    Found existing installation: discord 2.0.0
    Uninstalling discord-2.0.0:
      Successfully uninstalled discord-2.0.0
Successfully installed discord-1.7.3
pzserver@pzserver:~/zomboi$ python zomboi.py

It's look like 2.0.0 has been uninstall then 1.7.3 installed no ?

[EDIT]

I manually remove dist-package and try to reinstall project with good discord version has explain.

pzserver@pzserver:~/zomboi$ grep discord requirements.txt
discord==1.7.3

Here what I found pending the install.

Collecting discord.py>=1.7.3
  Downloading discord.py-2.0.1-py3-none-any.whl (1.1 MB)

That "Collecting discord.py>=1.7.3" make me download de last version anyway. So I also put discord.py==1.7.3 in the requirements.

Collecting discord.py==1.7.3
  Downloading discord.py-1.7.3-py3-none-any.whl (786 kB)

But now, here is what I found :

Traceback (most recent call last):
  File "/home/pzserver/zomboi/zomboi.py", line 14, in <module>
    from rcon_adapter import RCONAdapter
  File "/home/pzserver/zomboi/rcon_adapter.py", line 4, in <module>
    from rcon.source import Client, rcon
ModuleNotFoundError: No module named 'rcon.source'
JonnyPtn commented 1 year ago

yes but the bot is still using the 2.0 package from somewhere - parhaps you have it installed somewhere else or it's cached

afronob commented 1 year ago

yes but the bot is still using the 2.0 package from somewhere - parhaps you have it installed somewhere else or it's cached

Check my EDIT anwser, I found the thing. But...

Could you please give us each version of package requirements made for this bot ?

JonnyPtn commented 1 year ago

How can I refuse when you ask so nicely :)

I've just fixed the issues with discord 2 and set the versions in the requirements.txt to prevent this happening again: #51

Let me know if you still have issues with that

afronob commented 1 year ago

How can I refuse when you ask so nicely :)

I've just fixed the issues with discord 2 and set the versions in the requirements.txt to prevent this happening again: #51

Let me know if you still have issues with that

It's working like a charm, thanks!