【问题标题】:Coded a Discord and I think it doesn't see the rest of my code编码了一个不和谐,我认为它看不到我的其余代码
【发布时间】:2019-09-29 19:44:20
【问题描述】:

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

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)) 

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

【问题讨论】:

  • 不,格式不是“网站的制作方式”。请编辑问题以显示真实格式,否则您的问题将无法回答。
  • 它看起来像一个缩进问题。您的所有if 语句都应处于同一级别。照原样,如果第一个条件为真,您的代码只会检查第二个条件。

标签: python python-3.6 discord discord.py


【解决方案1】:
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))

【讨论】:

    猜你喜欢
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 2022-01-25
    • 2014-08-14
    • 1970-01-01
    • 2022-11-02
    相关资源
    最近更新 更多