2

I ran into an problem while trying to send a message to a specified channel when someone joins my discord. I got this Error:

Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:\Users\Timo\Anaconda3\envs\Discord\lib\site-packages\discord\client.py", line 270, in _run_event
    await coro(*args, **kwargs)
  File "C:/Users/Timo/PycharmProjects/Discord/Bot 1/Main.py", line 30, in on_member_join
    channel = Bot.get_channel("649275309396590626")
TypeError: get_channel() missing 1 required positional argument: 'id'

I'm using version v1.2.5. Here's the code:

@client.event
async def on_member_join(member):
    channel = Bot.get_channel("649275309396590626")
    await channel.send(f"{member} ist dem Server beigetreten!")

Here's the Bot Variable:

import discord
from discord.ext import commands
from discord.ext.commands import Bot

client = Bot(command_prefix=".")

I edited it to:

@client.event async def on_member_join(member): channel = client.get_channel("649275309396590626") await channel.send(f"{member} ist dem Server beigetreten!")

Now i have this Error:

File "C:/Users/Timo/PycharmProjects/Discord/Bot 1/Main.py", line 31, in on_member_join await channel.send(f"{member} ist dem Server beigetreten!") AttributeError: 'NoneType' object has no attribute 'send'
5
  • Can you show us more code? What does Bot look like? Commented Dec 29, 2019 at 19:53
  • This is the Bot Variable: import discord from discord.ext import commands from discord.ext.commands import Bot client = Bot(command_prefix=get_prefix) Commented Dec 29, 2019 at 20:00
  • Please add this to your answer so the information is formatted nicely and present for future readers! Commented Dec 29, 2019 at 20:01
  • Okay i added it to the Question. Commented Dec 29, 2019 at 20:07
  • Please feel free to upvote & accept my answer if it solves your problem. Otherwise, leave a comment to clarify! Commented Dec 29, 2019 at 20:08

2 Answers 2

0

The client.get_guild(id) function requires an integer input. When this is not correctly given or the id is invalid the function will return a None value. When you try to send something using the NoneType object you cause an error. As a NoneType object doesnt have a "send' function.

I recommend reading the documentation: https://discordpy.readthedocs.io/en/latest/api.html?highlight=get_guild#discord.Client.get_guild

Sign up to request clarification or add additional context in comments.

Comments

0

I found the problem, it is that i set an string as ID instead of an int. Now the code looks like this:

@client.event
async def on_member_join(member):
    channel = client.get_channel(649275309396590626)
    await channel.send(f"{member} ist dem Server beigetreten!")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.