【发布时间】:2020-05-11 21:54:09
【问题描述】:
我希望我的机器人在 on_ready 事件中上线时发送消息。该行在(on_message)中工作,但我无法让它在(on_ready)中发送一些东西
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
await message.channel.send('The bot is online ')
【问题讨论】:
-
欢迎来到stackoverflow!您发布的代码似乎没有任何问题。您能否包含更多上下文,或发布您收到的错误消息?
-
@ErtySeidohl 每次运行代码时都会出现此错误。 文件“D:/code/python/discord test/discordtest.py”,第 12 行,在 on_ready await message.channel.send('The bot is online') NameError: name 'message' is not defined。 我尝试将
message.channel.send('The bot is online ')更改为client .channel.send('The bot is online '),因为client = discord.Client()但它也不起作用。 -
@ErtySeidohl 使用
client .channel.send('The bot is online ')我收到此错误。 文件“D:/code/python/discord test/discordtest.py”,第 11 行,在 on_ready await client.channel.send('The bot is online') AttributeError: 'Client' object has no attribute 'channel '
标签: python bots discord python-asyncio