ValvePython / dota2

🐸 Python package for interacting with Dota 2 Game Coordinator
http://dota2.readthedocs.io
198 stars 32 forks source link

Problem with creation ChatChannel object #56

Closed CarryTI closed 3 years ago

CarryTI commented 3 years ago

I don't quite understand what data should be written to join_data I tried to send a message from the event there, but I got error.

Code:

@chat_manager.on(chat_manager.EVENT_JOINED_CHANNEL)
def setChat(joinData):
    chat = ChatChannel(channel_manager=chat_manager, join_data=joinData)

@dota.on(dota.EVENT_LOBBY_NEW)
def invite(lobby):
    dotaID = 32xxx3989
    steam_id = SteamID(dotaID).as_64.numerator
    dota.invite_to_lobby(steam_id=steam_id)
    chat_manager.join_lobby_channel()

Error: Traceback (most recent call last): File "src\\gevent\\greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run File "C:/files/projects/dota2/main.py", line 56, in setChat chat = ChatChannel(channel_manager=chat_manager, join_data=joinData) File "C:\files\projects\dota2\env\lib\site-packages\dota2\features\chat.py", line 246, in __init__ self.id = join_data.channel_id AttributeError: 'ChatChannel' object has no attribute 'channel_id' 2020-10-28T09:13:51Z <Greenlet at 0x1c31f72dbf0: setChat(<ChatChannel(789374, 'Lobby_26907975488097378', 3))> failed with AttributeError

rossengeorgiev commented 3 years ago

You don't need to instantiate ChatChannel you get an instance as the only parameter for that event. See https://dota2.readthedocs.io/en/stable/dota2.features.chat.html#dota2.features.chat.ChannelManager.EVENT_JOINED_CHANNEL

Here is an example:

dota_client = ....

@dota_client.channels.on(dota_client.channels.EVENT_JOINED_CHANNEL)
def on_channel_join(channel):
    print(channel)
    channel.send("Hi, I just joined this channel")
rossengeorgiev commented 3 years ago

Closing this due to inactivity