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 :)
Related
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! :)
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)
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
Making a command that allows a user to report a bug. I want it so you can include an image with the bug so you can show a visual example, except what I have does not work, and upon looking at the docs, this should work.
The problems I am having is that the embed is not sending. When I remove the bugEmbed.set_image() it works again.
#commands.command()
async def bug(self, ctx, *, bugReport=None):
"""Command that allows users to report bugs about the bug"""
channel = self.client.get_channel(864211572218265610)
bugEmbed = discord.Embed(
title=f"Bug Report",
description=bugReport,
color= 0xFFFF00
)
bugEmbed.add_field(
name="Reported by",
value=f"<#{ctx.author.id}>"
)
bugEmbed.set_footer(
text="",
icon_url=ctx.author.avatar_url
)
bugEmbed.set_image(
url=bugReport.attachments.url
)
if bugReport is None:
await ctx.send("You didn't include a bug with the report! Try again.")
await channel.send(embed=bugEmbed)
The problem is probably related to attachments being a list so you can't access an attribute called url, meaning you would have to do something like this:
if len(bugReport.attachments):
bugEmbed.set_image(
url=bugReport.attachments[0].url
)
Edit:
Ok so the problem is you are trying to get the attachments from the bugReport which is just the text you pass, what you actually want to do is get that data from the context (ctx)
if len(ctx.message.attachments):
bugEmbed.set_image(
url=ctx.message.attachments[0].url
)
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.
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 2 years ago.
Improve this question
the code doesn't work:
async def online(ctx, channel: discord.VoiceChannel.id('710791819524009066')):
await ctx.edit(name='Online:' + getonline())
Error:
async def online(ctx, channel: discord.VoiceChannel.id('710791819524309066')):
TypeError: 'member_descriptor' object is not callable
How fix it? Thanks.
You can't do discord.VoiceChannel.id('710791819524009066'), but you can do discord.VoiceChannel.id meaning
You could do:
async def online(ctx, channel: discord.VoiceChannel):
if channel.id == 664967449908609024: # Check if channel ID given is 664967449908609024
await ctx.send(content="Online " + getonline())
Command: online <channel ID> - Because we're using discord.VoiceChannel we can just give a channel ID if can't mention a voice channel.