【发布时间】:2021-07-06 18:37:57
【问题描述】:
大家好,我正在尝试让机器人在特定频道中自动发送消息。我获取了频道 ID 并将其传递给 if condition (a_string.find ('data: []')! = -1)。但是这段代码给了我这个错误。请参阅输出错误。
附:我正在使用 Replit,Live 是文件名 (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'
【问题讨论】:
-
你试过
client.get_channel(ID)吗?我假设你必须使用它。 -
是的,我试过了。它不起作用。语法错误
标签: python-3.x discord.py