Turf
Turf

Reputation: 444

Message in a specific Discord channel

Hi guys i'm trying to make the bot send a message automatically in a specific channel. I took the channel ID and pass it in the if condition (a_string.find ('data: []')! = -1). However this code gives me this error. See OUTPU ERROR.

P.S. I'm using Replit and Live is the file name (Live.py)

from discord.ext import commands
from Naked.toolshed.shell import execute_js, muterun_js
import sys

class Live(commands.Cog):
    def __init__(self,client):
        self.client=client
    
    @commands.Cog.listener()
    async def on_ready(self):
        channel = self.get_channel(828711580434169858)
        response = muterun_js('serverJs.js')
        original_stdout = sys.stdout # Save a reference to the original standard output
        if response.exitcode == 0:
                a_string= str(response.stdout)#stampa in console
                if (a_string.find('data: []') != -1):
                    print("Streamer: Offline ")
                else:
                    print("Streamer: Online")
                    await channel.send('Live Link: https://...link....')
        else:
            sys.stderr.write(response.stderr)

    @commands.command()
    async def Live(self,ctx):
        await ctx.send('')

def setup(client):
    client.add_cog(Live(client))

OUTPUT ERROR:

Ignoring exception in on_ready
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/home/runner/Solaris-IA/cogs/Live.py", line 12, in on_ready
    channel = self.get_channel(828711580434169858)
AttributeError: 'Live' object has no attribute 'get_channel'

Upvotes: 0

Views: 170

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15728

It's self.client.get_channel, not self.get_channel, you haven't defined that function

channel = self.client.get_channel(828711580434169858)

Upvotes: 1

Related Questions