【发布时间】:2020-11-07 01:02:18
【问题描述】:
我目前正在尝试使用 Python 制作一个 Discord 机器人,以自动化一些无聊的东西。我目前只是在尝试制作一些可以响应消息,然后发回的东西。
我的代码在这里:
import discord
TOKEN = '(The correct Token, hidden for obvious reasons)'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
await client.send(message.channel, msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
当我运行此代码时,机器人会出现在网上,并在有人键入 !hello 时识别出来。但是,紧接着,它在尝试发送消息“AttributeError: 'Client' object has no attribute 'send'”时返回错误
此时我已经在这里待了几个小时,如果有任何问题,我们将不胜感激
【问题讨论】: