how can I add context menu from app_commands - discord

I want to add context menu from app_commands, I tried that, but it didn't work
import discord
from discord import app_commands
from discord.ext import commands
#app_commands.context_menu(name="Hello")
async def hello(interaction: discord.Interaction, message: discord.Message):
await interaction.response.send_message("Hey !")
I'm using discord.py 2.0.1, how can I add?

Context menu's are a bit tricky to get working, here's an example:
async def hello(interaction: discord.Interaction, message: discord.Message):
await interaction.response.send_message(f"Hey {message.author.mention}!")
hello_context_menu = app_commands.ContextMenu(
name='Say Hello',
callback=hello,
)
bot.tree.add_command(hello_context_menu)

Related

will that work? its a bot that responds to messages from a certain user

import discord
from replit import db
from keep_alive import keep_alive
intents = discord.Intents.default()
client = discord.Client(intents=intents)
#client.event
async def on_message(message):
if message.author.id == "667020238340096000":
await message.channel.send("ok naplet")
keep_alive()
client.run(
"token goes here but i deleted it to share this")
will it work? help me

how to insert #client.event in #client.command just new to discord py program i hava a question about this followingcode

is it possiple to insert client.event on client.command
this is my code please explain this issue and add your code for future reference
import discord
from discord.ext import commands
import random
import asyncio
from random import randint
import aiohttp
from discord.ext.commands.core import command
client = commands.Bot(command_prefix = '')
client.remove_command('help')
#client.event
async def on_ready():
print('we are logged in {0.user}'.format(client))
#client.command()
async def say(ctx, *, args):
embed=discord.Embed(title= args, color=0x3700ff)
await ctx.send(embed=embed)
#client.event
async def on_message(message):
if message.content.startswith('stop'):
await message.channel.send('start')
#client.run("my token")
am try to understand why #client.event on_message will not working on #client.command
disclimer:- am noob on code so need a professionals help so thank about the helper

Firebase Reset Password Link (Did not receive) using firebase react native what's wrong in my code?

Firebase Reset Password Link (Did not receive) using firebase react native
import { sendPasswordResetEmail } from '#firebase/auth'
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
const onForgot = async (email) => {
const auth = firebase.auth();
await sendPasswordResetEmail(auth, email)
.then(() => {
alert("reset email sent to " + email);
})
.catch(function (e) {
console.log(e);
});
}
please help, and thanks in advance.
I am not sure how it works in react native. But in reactjs, the way we instantiate the auth is different from what I'm seeing here. We do something like this:
import Firebase from "../../Firebase/Firebase";
var auth = getAuth(Firebase);
//some code here e.g. your main function etc
sendPasswordResetEmail(auth, user.email)
.then(() => {
message.success("Password reset email sent!")
})
.catch((error) => {
message.error("Unable to send reset password link :: " + error.message)
});
Just verify whether you are indeed getting your "auth" instantiated in the right way here. A simple import doesn't cut it.
EDIT: My code is using version 9 of firebase. Please check with the version you are using and make sure your auth is being instantiated right according to the version
EDIT 2: Remember to enable firebase auth "email sign in" in the firebase console authentication section
All the best.
If you're not getting an error back from the call to sendPasswordResetEmail, there is likely nothing wrong with your code. More likely the message was sent, but got stuck in a spam filter or spam box. So check your spam folder to see if the message showed up there.

AttributeError: 'Client' object has no attribute 'get_all_emojis'

from distutils.util import change_root
from discord.utils import get
import discord
import random
import shutil
client = discord.Client()
#client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
#client.event
async def on_message(message):
channel = client.get_channel(968268255804420096)
emoji = await discord.utils.get(client.get_all_emojis(), name='upvote')
await client.add_reaction(message, emoji)
i'm trying to make a bot react to all messages in a specific channel, but i keep getting the "AttributeError: 'Client' object has no attribute 'get_all_emojis'" error
any help?
This no longer works because get_all_emojis was removed a long time ago. Instead, use client.emojis.
emoji = discord.utils.get(client.emojis, name='upvote')

Discord.py not unpinning own bot's messages

My test code is
#bot.command(name='test')
async def test(ctx):
message = await ctx.send('test')
channel = ctx.channel
message = await channel.fetch_message(message.id)
await message.pin()
await message.unpin()
The bot pins the message but it won't unpin it.
I tested the code, it works fine for me.
NOTE- Discord only shows a message that someone has pinned the message, but discord does not show if someone has unpinned it, you need to check it in the pinned messages.
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix = '!')
#bot.event
async def on_ready():
print('Logged successfully!')
#bot.command()
async def test(ctx):
message = await ctx.send('test')
await message.pin()
await message.unpin()
bot.run('BOT_TOKEN_HERE')

Resources