【发布时间】:2020-06-30 08:40:06
【问题描述】:
所以我最近创建了一个包含各种 meme 命令和审核命令的不和谐机器人。我对 python 比较陌生,但我理解它的要点。我已经创建了一个命令,让我(只有我)通过机器人 DM 用户。我现在想尝试让机器人能够读取发回给它的消息并将它们发送给我,无论是打印在 shell 中还是发送到特定的频道/我,我不在乎,我只想能够看到发送给它的内容。 我做了一些阅读,找到了this,并从中收集了这个:
@bot.event
async def on_message(message):
channel = bot.get_channel('channel ID')
if message.server is None and message.author != bot.user:
await bot.send_message(channel, message.content)
await bot.process_commands(message)
仅此一项对我不起作用,当我对机器人进行 DM 管理时,我收到一条错误消息,提示“AttributeError:'Message' 对象没有属性 'server'”。有人告诉我 discord.py rewrite 不使用“服务器”,而是使用“公会”。所以我把它改成了message.guild。从那里它给了我错误“AttributeError:'Bot'对象没有属性'send_message'”,这就是我到达那里的程度。我已经对其进行了修补,并在这里和那里改变了一些东西,并取得了一些轻微的进展......我想。我的新代码是:
@bot.event
async def on_message(ctx, message):
channel = bot.get_channel('channel ID')
if message.guild is None and message.author != bot.user:
await ctx.send(channel, message.content)
await bot.process_commands(message)
这给了我错误“TypeError: on_message() missing 1 required positional argument: 'message'”。 这就是我现在所得到的。任何帮助都将不胜感激,正如我所说,我对 python 还有些陌生,我大约 2 个月前才开始使用它。
【问题讨论】:
标签: python bots discord discord.py discord.py-rewrite