如何解决这个错误discord python?

时间:2018-01-26 22:03:36

标签: python discord discord.py

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 + '**"')

当我在不和谐中写下这个命令时:

!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

1 个答案:

答案 0 :(得分:0)

因为你键入了这个:

!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(list)连接两个字符串。这是不可能的。

你可能想要的是msg是一个字符串,因此你应该使用:

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

msg重新恢复原状:

msg = "reason, reason and reason"