I can't send ctx messages as ephemeral it says:
AttributeError: 'Context' object has no attribute 'respond'
await ctx.respond("This is suposed to be ephemeral", ephemeral=True)
So How ctx can be ephemeral ?
It only works with interaction ?
EDIT :
tried this
await ctx.reply("This is suposed to be ephemeral", ephemeral=True)
So How ctx can be ephemeral?
It can't.
It only works with interaction?
Yep, exactly.
Related
channel = bot.get_channel(id_of_the_channel)
message = await channel.fetch_message(id_of_the_message)
I tried to use this code so that a bot could edit its own message, but there's an error on the line with "fetch_message".
File "main.py", line 280, in on_message
message = await channel.fetch_message(messageid)
AttributeError: 'NoneType' object has no attribute 'fetch_message'
So get_channel only returns the channel object if it's in the cache - if it's returning None then it's not. It is returning None as per the error message. To fix:
channel = await bot.fetch_channel(id_of_the_channel)
message = await channel.fetch_message(id_of_the_message)
This should resolve that issue.
I'm trying to build a bot that changes the name of a channel when someone joins. Here's my code:
#client.event
async def on_member_join(guild):
await update_channel(guild)
new_name = f"{member_count(guild)}"
await channelid.edit(name=new_name)
channelid = *redacted*
def update_channel(guild):
return len(guild.members)
However, I get this error:
AttributeError: 'Member' object has no attribute 'members'
What's the reason for this error, and how can I resolve it?
You have imported the wrong module, You should import the Guild module instead of the Member module, as mentioned in this documentation, members is an attribute from class discord.Guild
See this for more details:
Discord API Reference
This error appears after starting the program:
await client.edit_profile(password=discordpass, username=Name)
AttributeError: 'Client' object has no attribute 'edit_profile'
According to this Github comment, you have to do:
await client.user.edit(password=discordpass, username=Name)
(Insert greetings)
I wanted to make the discord bot reply to a message which was replied to in the command message,below is the code so far:
#bot.command(brief="Iri? Bilang Bos!", description="Iri? Bilang Bos!")
async def iri(ctx):
ref = ctx.reference
x=['https://i.imgur.com/8mfw6Nv.jpg', 'https://tenor.com/view/iri-bilang-bos-spell-power-up-skill-gif-17176211', 'https://i.imgur.com/hOvruLZ.jpg']
await ctx.delete()
await ctx.send(random.choice(x), reference=ref)
This raises the exception AttributeError: 'Context' object has no attribute 'reference'
How do i solve this? Thanks.
You have the right idea but didn't look into documentation enough. Usually if you don't know what attribute you need to use it's helpful to search in the documentation.
Context doesn't have attribute reference. That is because reference is an attribute of our message. Luckily for us context (ctx) has a message attribute: ctx.message. We use this to to get the message object which we then use to get the reference attribute: ctx.message.reference.
The same goes for the delete method. Context object doesn't have delete method so we first need to get the message object: ctx.message and then use the delete method of the message object: await ctx.message.delete() (We have to use await because the delete method is asynchronous)
Note: It's usually good practise to give your variables meaningful names. It improves the readability of your code. That's why I changed your x variable to choices
So the end result should be something like this:
#bot.command(brief="Iri? Bilang Bos!", description="Iri? Bilang Bos!")
async def iri(ctx):
ref = ctx.message.reference
choices = ['https://i.imgur.com/8mfw6Nv.jpg', 'https://tenor.com/view/iri-bilang-bos-spell-power-up-skill-gif-17176211', 'https://i.imgur.com/hOvruLZ.jpg']
await ctx.message.delete()
await ctx.send(random.choice(choices), reference = ref)
Hopefully this answers your question :)
I need help getting my bot to work
# Import Discord Package
import discord
# Client (our bot)
client = discord.Client()
#client.event
async def on_ready():
# DO STUFF....
general_channel = client.get_channel()
await general_channel.send('yo')
# Run the client on the server
client.run('')
when I run it i get AttributeError: 'NoneType' object has no attribute 'send' in terminal and nothing shows up on discord if you could fix it that would be great
The common reasons why get_ would return None are:
a) The channel ID is not found
b) The bot is not connected
c) get_ method is called before the bot is started.
In your case there are 2 obvious misses
get_channel method requires a parameter which is the channel ID.
https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.get_channel
The bot is likely not loggedIn as client.run() also requires a token parameter. client.run('your_token')