discord.py 'Bot' 对象没有属性 'send_message'
Posted
技术标签:
【中文标题】discord.py \'Bot\' 对象没有属性 \'send_message\'【英文标题】:discord.py 'Bot' object has no attribute 'send_message'discord.py 'Bot' 对象没有属性 'send_message' 【发布时间】:2020-12-17 10:55:56 【问题描述】:我的 python 脚本以以下几行结尾:
Task exception was never retrieved
future: <Task finished coro=<time_check() done, defined at rewards.py:18> exception=AttributeError("'Bot' object has no attribute 'send_message'")>
Traceback (most recent call last):
File "rewards.py", line 25, in time_check
await client.send_message(channel, messages)
AttributeError: 'Bot' object has no attribute 'send_message'
我不知道为什么会出现这个错误。有人可以帮我解决吗?
我已将 client = commands.Bot(command_prefix='.') 更改为 client = discord.Client() 但错误似乎相同。
Task exception was never retrieved
future: <Task finished coro=<time_check() done, defined at rewards.py:19> exception=AttributeError("'Client' object has no attribute 'send_message'")>
Traceback (most recent call last):
File "rewards.py", line 26, in time_check
await client.send_message(channel, messages)
AttributeError: 'Client' object has no attribute 'send_message'
这是我使用的 python 机器人。他们应该在特定时间发布消息。
import asyncio
from datetime import datetime
from discord.ext import commands
TOKEN = 'NzQ4ODc1MXXXXXXXXXXXXXXXXXXXXRKO4ORH0'
client = commands.Bot(command_prefix='.')
alarm_time = '15:25'
channel_id = '748XXXXXXXXXX5'
@client.event
async def on_ready():
print('Bot Online.')
async def time_check():
await client.wait_until_ready()
while not client.is_closed():
now = datetime.strftime(datetime.now(), '%H:%M')
channel = client.get_channel(channel_id)
messages = ('Test')
if now == alarm_time:
await client.send_message(channel, messages)
time = 90
else:
time = 1
await asyncio.sleep(time)
client.loop.create_task(time_check())
client.run(TOKEN)
【问题讨论】:
***.com/questions/48116872/… 【参考方案1】:如果不起作用,请替换 await channel.send_message(messages)
而不是 await client.send_message(channel, messages)
,请尝试 await channel.send(messages)
。这对你有用。
【讨论】:
await channel.send_message(messages) 也会带来以下错误。 AttributeError:“NoneType”对象没有属性“send_message” 将channel_id
变量的值更改为真实的频道ID。
同样的错误。 AttributeError: 'NoneType' 对象没有属性 'send'
你确定channel_id
有一个真实的频道吗?
机器人是否拥有查看该频道所需的权限?以上是关于discord.py 'Bot' 对象没有属性 'send_message'的主要内容,如果未能解决你的问题,请参考以下文章
Discord Bot 响应短语(Discord.py 重写)
Discord bot 添加对消息 discord.py 的反应(无自定义表情符号)