首页 > 解决方案 > 编码了一个不和谐,我认为它看不到我的其余代码

问题描述

我做了一个代码,这里是:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('Hello'):
            await message.channel.send('Hello {0.author.mention}'.format(message))

            if message.content.startswith('G!Help'):
                await message.channel.send('Hello {0.author.mention} Here are some commands you can use: Who, Yeet, Why, Help'.format(message))

                if message.content.startswith('G!Who'):
                    await message.channel.send('You are {0.author.mention} WOW!'.format(message))

                    if message.content.startswith('G!Yeet'):
                        await message.channel.send('{0.author.mention} Yeet!'.format(message))

                        if message.content.startswith('G!Why'):
                            await message.channel.send('Erm, {0.author.mention} Why What?'.format(message))


client = MyClient()
client.run('Insert token here')

抱歉格式化,这就是网站的制作方式,所以,从

if message.content.startswith('G!Help'):
                await message.channel.send('Hello {0.author.mention} Here are some commands you can use: Who, Yeet, Why, Help'.format(message)) to  if message.content.startswith('G!Why'):
                            await message.channel.send('Erm, {0.author.mention} Why What?'.format(message)) 

它不起作用,有什么帮助吗?并且此处的插入令牌有一个令牌,只是我删除了它,因为我不想泄漏它,非常感谢帮助。

标签: pythonpython-3.6discorddiscord.py

解决方案


import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('Hello'):
            await message.channel.send('Hello {0.author.mention}'.format(message))

        elif message.content.startswith('G!Help'):
            await message.channel.send('Hello {0.author.mention} Here are some commands you can use: Who, Yeet, Why, Help'.format(message))

推荐阅读