如何修复此错误不一致 python?

How to fix this error discord python?

if message.content.lower().startswith('!kick') and (roleLFJob in message.author.roles or roleLFAba in message.author.roles):
    await client.delete_message(message)
    serverchannel = '405090256124248065'
    messageParsed = message.content.split()
    kick = messageParsed[0]
    mention = messageParsed[1]
    msg = messageParsed[2:]
    for member in message.mentions:
        await client.kick(member)
        await client.send_message(discord.Object(id=serverchannel), '{0} was kicked by {1}, with reason:"**'.format(member.mention, message.author.mention) + msg + '**"')

当我在 discord 中写这个命令时:

!kick @(member.mention) reason, reason and reason

发生此错误:

Ignoring exception in on_message Traceback (most recent call last):  
File "C:\Users\senuk\AppData\Local\Programs\Python\Python35\lib\site-packages\discord\client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)   
File "overmind.py", line 128, in on_message
    await client.send_message(discord.Object(id=serverchannel), '{0} was kicked by {1} with reason:"**'.format(member.mention, message.author.mention) + msg + '**"') 
TypeError: Can't convert 'list' object to str implicitly

自从您输入:

!kick @(member.mention) reason, reason and reason

那么当你拆分整个内容时:

messageParsed = message.content.split()
kick = messageParsed[0]
mention = messageParsed[1]
msg = messageParsed[2:]

结果将是:

kick = "!kick"
mention = "@(member.mention)"
msg = ["reason,", "reason", "and", "reason"]

在代码的最后一行,您尝试用 msg(列表)连接两个字符串。这是不可能的。

您可能希望 msg 成为一个字符串,因此您应该使用:

msg = " ".join(messageParsed[2:])

msg 重制为原来的形式:

msg = "reason, reason and reason"