Reputation: 263
I'm using discordpy to teach myself to understand how to create a Discord bot, and I've run into a problem. I have a test server with myself and a bot that I created. I am trying to test something, so I type some test text in a channel and wait for the code to respond, but I did not get a response. I decided to check something using guild.members
but it returned the following:
[<Member id=762523114939613204 name='MrScript-BotClone' discriminator='6549' bot=True nick=None guild=<Guild id=762530852977901619 name='bot testing grounds' shard_id=None chunked=False member_count=2>>]
Why doesn't this recognize my own user as well?
function in question
async def check_donation(message):
data = json.loads(message.content.split("\n")[0])
target = message.guild.get_member_named(data["user"])
amount = data["amount"]
print(message.guild.members) # this is where im testing for members
# call donation if member exists
if target:
functions.donation(target, amount)
main.py
@client.event
async def on_message(message):
# if not in server or user is bot, ignore
if message.author.bot or not message.guild:
return
# if user is not verified, start verif process
if message.content and not await functions.is_verified(message.author):
await generate_invite(message.author)
await message.delete()
return
# setup user data if it doesn't already exist
await functions.setup_data(message.author)
# interpret command if starts with prefix
if message.content.startswith(data.prefix):
command_exists = await interpret_command(message)
if not command_exists:
await message.add_reaction("❌")
# check if message is a donation
if message.channel.id == data.donation_channel:
await messages.check_donation(message)
# check message for spam, award points and such
await messages.handle(message)
Upvotes: 1
Views: 586
Reputation: 343
You need to enable the "members" intent otherwise discord will not send members. You can read up on intents here https://discordpy.readthedocs.io/en/latest/intents.html. A quick example would look like:
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
Upvotes: 1