首页 > 解决方案 > Python:我不确定为什么我的不和谐机器人代码会出现此错误

问题描述

我正在尝试使用 mega.py 制作一个不和谐的机器人,它将在 mega.nz 上搜索您的文件,但给了我一些错误,我不知道这意味着什么。该命令将是 >find(无论您想在 MEGA 存档中获取什么,在我的情况下是 mp3 文件),并且我希望机器人将 MEGA 链接发送到 Discord 频道中请求的文件。这是我在 python 中的第一个项目,我希望我能克服这个错误。

这是错误。

TypeError: unsupported operand type(s) for +: 'member_descriptor' and 'str'

这是当前的代码。

import discord
from discord.ext import commands
from mega import Mega

client = commands.Bot(command_prefix=">")

@client.event
async def on_ready():
    await client.change_presence(status=discord.Status.dnd)
    print('it worked?')

@client.event
async def on_message(find):
    mega = Mega()
    song = discord.Message.content
    m = mega.login("email", "password")
    file = m.find(song + '.mp3')
    link = m.get_link(file)
    if file:
        await ctx.send(link)
   

client.run('token')

标签: python

解决方案


如果我正确理解了 python 的不和谐 API async def on_message,则接受一个输入,即消息。在这一行:

song = discord.Message.content

当你真的应该做的时候,你将歌曲设置为与不和谐库相关的东西:

song = find.content

这是一个字符串。


推荐阅读