我的Discord Bot返回“AttributeError:'str'对象没有属性”

时间:2017-10-09 16:36:52

标签: python discord discord.py

我正在Python上构建一个简单的discord bot,在输入的每个字符和其他一些东西之间放置空格。

我的代码在这里:

public void OnTriggerEnter2D(Collider2D target)
    {
        if (target.gameObject.name == "bird1" || target.gameObject.name == "bird2" || target.gameObject.name == "bird3" || target.gameObject.name == "bird4" || target.gameObject.name == "bird5" || target.gameObject.name == "bird6" || target.gameObject.name == "bird7" || target.gameObject.name == "bird8" && f < 8)
        {
            f++;
            propPAnel8.SetActive(true);
            BirdText.text = "x " + f;
            if (f == 8)
            {
                bound8.isTrigger = true;
            }
        }
    }

但是当我在discord上写import discord import asyncio client = discord.Client() def bos(a): a=a.upper() a=a.replace("0", "SIFIR") a=a.replace("1", "BİR") a=a.replace("2", "İKİ") a=a.replace("3", "ÜÇ") a=a.replace("4", "DÖRT") a=a.replace("5", "BEŞ") a=a.replace("6", "ALTI") a=a.replace("7", "YEDİ") a=a.replace("8", "SEKİZ") a=a.replace("9", "DOKUZ") a=" ".join(a) @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') @client.event async def on_message(message): if message.content.startswith('*'): a = message.content[1:] await client.send_message(message.channel, a.bos(a)) #counter = 0 #tmp = await client.send_message(message.channel, 'Calculating messages...') #async for log in client.logs_from(message.channel, limit=100): # if log.author == message.author: # counter += 1 #await client.edit_message(tmp, 'You have {} messages.'.format(counter)) #elif message.content.startswith('!sleep'): #await asyncio.sleep(5) #await client.send_message(message.channel, 'Done sleeping') client.run('token') 时,终端返回:

*test

有人可以帮我修复此代码吗?

2 个答案:

答案 0 :(得分:0)

bos不是str上的方法;它是一个全球范围的功能。而不是a.bos(a),只需使用bos(a)

答案 1 :(得分:0)

str是常规函数,而不是a方法。此外,在函数内部分配def bos(a): return " ".join(a.upper(). replace("0", "SIFIR"). replace("1", "BİR"). replace("2", "İKİ"). replace("3", "ÜÇ"). replace("4", "DÖRT"). replace("5", "BEŞ"). replace("6", "ALTI"). replace("7", "YEDİ"). replace("8", "SEKİZ"). replace("9", "DOKUZ")) ... await client.send_message(message.channel, bos(a)) # ^^^^^^ 不会影响调用之外的参数;你需要返回一个新的字符串。

DisplayMember