【发布时间】:2020-08-30 23:05:41
【问题描述】:
我是使用 discord.py 的新手,基本上我只是想让我的 discord 机器人说点什么然后删除以前的文本,所以例如我想输入“/say hello”然后我希望机器人抓住那个,删除前缀并打印“你好”,我已经用谷歌搜索并找到了另一个指南,但没有后续答案,当我尝试他们错误的解决方案时,下面是我使用的代码
import discord
from discord.ext import commands
bot = discord.Client()
prefix = "/"
@bot.event
async def on_ready():
print("Online")
@bot.event
async def on_message(message):
args = message.content.split(" ")[1:]
if message.content.startswith(prefix + "say"):
await bot.delete_message(message)
await bot.send_message(message.channel, " ".join(args))
bot.run("token")
这是控制台打印出来的错误
C:\Users\unknownuser\anaconda3\envs\discordbot\pythonw.exe C:/Users/unknownuser/PycharmProjects/discordbot/bot.py
Online
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\unknownuser\anaconda3\envs\discordbot\lib\site-packages\discord\client.py", line 313, in _run_event
await coro(*args, **kwargs)
File "C:/Users/unknownuser/PycharmProjects/discordbot/bot.py", line 15, in on_message
await bot.delete_message(message)
AttributeError: 'Client' object has no attribute 'delete_message'
当我开始学习它背后的文档和逻辑时,我应该开始自己弄清楚,但这个让我很难过,不胜感激
【问题讨论】:
标签: python discord discord.py discord.py-rewrite