title: Discord.py can't define channel [fixed]
body: <p>I'm making a discord bot that sends a welcome message to a specified channel in the .jason file. So it could be compatible with multiple servers. But it runs into an error and I can't figure out how to fix it.</p>
  <pre><code>@client.command()
  @commands.has_permissions(administrator=True)
  async def welcomeMessage(ctx):
      with open(&quot;guild.json&quot;, &quot;r&quot;) as f:
          guildInfo = json.load(f)
  
      guildInfo[ctx.message.guild.id] = ctx.message.channel.id #sets the channel it was sent to as the default welcome message channel
  
      with open(&quot;guild.json&quot;, &quot;w&quot;) as f:
          json.dump(guildInfo, f)
  
  
  @client.event
  async def on_member_join(member):
      with open(&quot;guild.json&quot;, &quot;r&quot;) as f:
          guildInfo = json.load(f)
  
      channel = guildInfo[ctx.message.guild.id] #this keeps causing the error
      
      embed = discord.Embed(colour=0x07faf6, description=f&quot;***Welcome to the Server***&quot;)
      embed.set_thumbnail(url=f&quot;{member.avatar_url}&quot;)
      embed.set_author(name=f&quot;{member.name}&quot;, icon_url=f&quot;{member.avatar_url}&quot;)
      embed.set_footer(text=f&quot;{member.guild}&quot;, icon_url=f&quot;{member.guild.icon_url}&quot;)
      embed.timestamp = datetime.datetime.utcnow()
      await channel.send(embed=embed)
  </code></pre>
  <p>I have got everything working except this:</p>
  <pre><code>channel = guildInfo[ctx.message.guild.id]
  </code></pre>
  <p>It keeps giving me this error:</p>
  <pre><code>    channel = guildInfo[ctx.message.guild.id]
  AttributeError: module 'ctx' has no attribute 'message'
  </code></pre>
  <p>EDIT:
  I redid the code and now it works.</p>
  <p>here it is:</p>
  <pre><code>@client.command(pass_context=True)
  @commands.has_permissions(administrator=True)
  async def welcomechannel(ctx):
      fileopen = str(ctx.message.guild.id) + &quot;.json&quot;
      file = open(fileopen, &quot;w&quot;)
      data = {}
      data[&quot;channel&quot;] = ctx.message.channel.id
      json.dump(data, file)
      print(&quot;The channel has been added to the list&quot;)
  
  @client.event
  async def on_member_join(member):
      colours = [0x3348FF, 0x000000, 0xFFFFFF]
      try:
          fileopen = str(member.guild.id) + &quot;.json&quot;
          file = open(fileopen, &quot;r&quot;)
          data = json.load(file)
  
          channelid = data[&quot;channel&quot;]
          channel = client.get_channel(id=channelid)
  
      
          embed = discord.Embed(colour=random.choice(colours), description=&quot;***Welcome***&quot;)
          embed.set_thumbnail(url=f&quot;{member.avatar_url}&quot;)
          embed.set_author(name=f&quot;{member.name}&quot;, icon_url=f&quot;{member.avatar_url}&quot;)
          embed.set_footer(text=f&quot;{member.guild}&quot;, icon_url=f&quot;{member.guild.icon_url}&quot;)
          embed.timestamp = datetime.datetime.utcnow()
          
          await channel.send(embed=embed)
  
      except:
          print(&quot;The server doesn't have a welcome channel&quot;)
  </code></pre>