使用python创建discord bot。无法使bot同时执行两个任务,但如果只运行一个任务,则代码可以工作

使用python创建discord bot。无法使bot同时执行两个任务,但如果只运行一个任务,则代码可以工作,python,discord,Python,Discord,我是python新手,所以我看不出哪里出错了。 进口不和 导入操作系统 从配置导入令牌 client = discord.Client() #Sends a message in terminal if it has worked @client.event async def on_ready(): print('We have logged in as {0.user}' .fo

我是python新手,所以我看不出哪里出错了。 进口不和 导入操作系统 从配置导入令牌

        client = discord.Client()
        
    #Sends a message in terminal if it has worked
        @client.event
        async def on_ready():
          print('We have logged in as {0.user}'
          .format(client)) 
        
       #Sends a message if !test is included in a sent message 
        @client.event
        async def on_message(message):
          if message.author == client.user:
            return
           
          if message.content.startswith('!test'):
           await message.channel.send('test')

@client.event
async def on_member_join(self, member):
  guild = member.guild
  if guild.system_channel is not None:
    to_send = 'Welcome {0.mention} to {1.name}'.format(member, guild)
    await guild.system_channel.send(to_send)
        
        client.run(TOKEN)

你的代码没有很好的缩进,这可能是问题所在。你的打印应该在一行中:print('我们以{0.user}.format(client')的身份登录)。我同意Salem的观点,缩进可能是问题所在,否则在运行代码时添加一点解释可能是明智的。什么有效,什么无效?你看到了什么错误?我还建议您使用Microsoft Visual Studio之类的工具来自动捕获一些较小的问题(如缩进)。@kevinvi8很抱歉,缺少详细信息。问题是,当出现以下情况时,发送消息的代码块!测试被发送,当有人加入服务器时发送消息的块将无法同时工作,因此如果我删除!测试代码连接代码将工作,反之亦然,但如果两者都在一起,只有一个将工作。缩进是这样的,因为我复制并粘贴到问题区域。谢谢你的邀请help@SalemJebnoun我修复了打印错误,但它没有改变任何东西,缩进只是网站上的一个问题,因为我复制并粘贴到问题字段中。谢谢你的帮助!