I am trying to make my bot send a welcome message when someone joins a specific server.
Code:
if member.guild.id == 928443083660607549:
new = nextcord.utils.get(member.guild.roles, name="new")
channel = bot.get_channel(996767690091925584)
embed = nextcord.Embed(title="welcome to ikari!", description="・make sure to read the rules in <#928443083698360397> \n ・for more questions refer to <#928507764714651698>", color=0x303136)
embed.set_author(name=f"{member.name}#{member.discriminator}", icon_url=member.display_avatar_url)
embed.set_thumbnail(url=member.guild.icon.url)
await channel.send(f"{member.mention}!", embed=embed)
await member.add_roles(new)Error:
Error:
AttributeError: 'Member' object has no attribute 'display_avatar_url'
Discord.py v2 changed the variables. Meaning that .avatar_url is now .avatar.url. .icon_url is now .icon.url. Hence meaning that member.display_avatar.url is what you're looking for.
This also means that stuff like .avatar_with_size(...) for example have now been changed to .avatar.with_size(...). Just for future reference.
Discord.py now has different variables for display avatars etc.
Just edit this line:
embed.set_author(name=f"{member.name}#{member.discriminator}", icon_url=member.display_avatar_url)
to
embed.set_author(name=f"{member.name}#{member.discriminator}", icon_url=member.display_avatar.url)
If this answer has worked, please mark it as the correct answer! :)
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
In the code below I am trying to give a person a role when they react to my message by using an emoji but this code throws me an error saying that 'Nonetype' has no attribute 'id' Anyone has any idea on how to solve this?
import discord
from discord.ext import commands
import random
client = discord.Client()
#client.event
async def on_ready():
print('ready')
#client.event
async def on_reaction_add(reaction, user):
role = discord.utils.get(user.guild.roles, name='Test_Bot')
await user.add_roles(role, reason='reason')
client.run('TOKEN')
We Should Always Try to Check That What is result we are getting
role = discord.utils.get(user.guild.roles, id='901100841438695534')
here you can just add one extra line to Check Whats Wrong
print(role)
here if you Get None , then the Error will be Given back to you, Just Remove the Blockquotes and youre fine :)
Also another thing i mention , Give The whole Traceback of the Code to make us understand easier :)
PS: After edit you Changed you are still not getting the Value of the role
as Maybe you have written a normal string role =
role = discord.utils.get(user.guild.roles, name='Test_Bot')
role = discord.utils.get(user.guild.roles,name=("Test_Bot"))(you need a extra tuple like form)
also the roles are case sensitive so make sure to use original word
Also print the role to make sure its right
TY :)
I am making a bot that has a database of things and sometimes someone would want to see what things a different person has, this would be possible by using discord id, but I just don't was everyone sending their discord ids around.
I was trying to use something like this:
def get_user_id(name_en, tag_en, guild_id):
guild = client.get_guild(guild_id)
user = discord.utils.get(guild.members, name= "Atom" , discriminator= "#1803")
print(user)
But that just outputs an empty message.
So is there a way to get a discord id from a username?
Also is this possible with making the discord bot in a different programming language? (if not possible in discord.py)
Thanks
You can use Guild.get_member_named()
The name can have an optional discriminator argument, e.g. “Jake#0001” or “Jake” will both do the lookup. However the former will give a more precise result. Note that the discriminator must have all 4 digits for this to work.
def get_user_id(name_en, tag_en, guild_id):
guild = client.get_guild(guild_id)
user = guild.get_member_named(name_en)
print(user)
So i am making a ticket bot for my Discord server so users can ask staff questions. And I am doing this by following this YouTube tutorial. The person in the video uses Cogs but I am not planning on doing so since the bot only does tickets. A bit further in the video when he start actually creating the ticket there is a part where he users #commands.Cogs.listener() but since I am not planning on using Cogs I don't know what I should put there instead.
I have tried #bot.listener() but that gave me the following error:
AttributeError: 'Bot' object has no attribute 'listener'
I have also tried #bot.Cogs.listener but that also did not work, and it gave me almost the same error.
AttributeError: 'Bot' object has no attribute 'Cogs'
So my question is, what do I put in instead?
Here is my code so you can see what I need to do.
#bot.Cogs.listener()
async def on_raw_reaction_add(payload):
if payload.member.id != bot.used.id:
with open('ticket.json', 'r') as file:
ticket_data = json.load(file)
You can use bot.add_listener or #bot.listen/#bot.event instead.
So I'm attempting to write a raiding bot for my raiding discord using the discord.py library in python. This scripts is supposed to be forming a list of members in the voice channel for raiding. For some reason, this script is not working. Whenever memids is printed, it just prints an empty list.
If anyone is familiar with discord.py and could tell me why this isn't working, please do. It's really troubling me and I have tried everything in my knowledge to fix it.
#find raiding
voice_channel = discord.utils.get(ctx.message.server.channels, id = '440014722587426816')
#finds the members
members = voice_channel.voice_members
memids = []
for member in members:
memids.append(member.id)
print(memids)
If you know the id of the channel you can do it this way. Works for me :D
channel = client.get_channel(1234567890) #gets the channel you want to get the list from
members = channel.members #finds members connected to the channel
memids = [] #(list)
for member in members:
memids.append(member.id)
print(memids) #print info
I faced the same problem. voice_channel.members would return either empty or incomplete lists some times.
The docs say:
voice_states
Returns a mapping of member IDs who have voice states in this channel.
Note: This function is intentionally low level to replace members when the member cache is unavailable.
https://discordpy.readthedocs.io/en/latest/api.html#voicechannel
I guess the members can't be trusted to return accurate connected member list consistently.
I solved this problem with the following code:
member_ids = voice_channel.voice_states.keys()
You need to enable "SERVER MEMBERS INTENT:
If your bot tracks server members or downloads the entire member list, you may need the server members intent to receive member events and the member list." on the discord developer page on the bot tab.
There isn't much to go on from your question. I believe your problem is that the id that you provided to utils.get(...) isn't the correct id of the voice channel. This is probably the reason to why you're always getting an empty list.
voice_members
A list of Members that are currently inside this voice
channel. If type is not ChannelType.voice then this is always an empty
array.
If you're not fully sure about the voice channel's actual id, I suggest you search by the name and type (discord.ChannelType.voice):
voice_channel = discord.utils.get(ctx.message.server.channels, name="channelname", type=discord.ChannelType.voice)
I you know the channel id, I suggest using
voice_channel = client.get_channel(channel_id)
instead (documentation here). If you're using discord.py-rewrite, you can also use:
voice_client = ctx.guild.get_channel(channel_id)
if the channel you're looking for is in the context guild (documentation here).
I want to put the avatar and nick of the person who ran a command in the embed, something like this:
requested by:
(avatar) (nick)
but I do not know how to start....
sounds like you should read more documentation, here are a few links:
rewrite: embed, send
async: embed, send_message
otherwise here is the code that I recommend using
em = discord.Embed(description='requested by:\n{0}'.format(ctx.author))
em.set_thumbnail(url=ctx.author.avatar_url)
# for rewrite (1.0.0a) do
await ctx.send(embed=em)
# if you're using async 0.16.x do
await bot.say(embed=em)
I used this:
embed.set_thumbnail(url=message.author.avatar_url)
embed.set_footer(text='ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤRequested by: ' + message.author.name)
Theres a pretty handy tool online that you can use to create embeds using discord.py.
Heres a link to it: Discord Embed Generator.
However, I highly suggest also reading the docs, to get a better understanding of what you're coding, instead of depending on that resource.
Heres the embed documentation.