I am trying to react to my bot own messages. But it does not work.
if args[0] == "solido":
reaction = "👍"
sent = await ctx.message.channel.send(client.get_channel("795387716967333889"), embed=embed)
# await message.add_reaction(sent, emoji = "\U0001F44D")
await ctx.message.add_reaction(reaction)
if I use this type of code, the bot will react to MY message commands. But if i dont use the ctx method the bot will give me this error: NameError: name 'message' is not defined
How could I fix?
using await sent.add_reaction(reaction) instead of await ctx.message.add_reaction(reaction) should work
Related
Trying to implement embedded messages for my discord bot using interactions. The following is the code with the error message under it.
import interactions
import discord
bot = interactions.Client(token="<REDACTED>")
#bot.command(
name="test",
description="Tests"
)
async def test(ctx: interactions.CommandContext):
embed = interactions.Embed(
title="testing",
description="test purposes"
)
await ctx.send(embed = embed)
Error Message:
payload = await super().send(content, **kwargs)
TypeError: _Context.send() got an unexpected keyword argument 'embed'
interactions.py documentation said This is quite simple: The argument embed got deprecated by Discord. The new naming is embeds.
Changed embed into embeds and it works now.
#bot.command(
name="test",
description="Tests"
)
async def test(ctx: interactions.CommandContext):
embeds = interactions.Embed(
title="testing",
description="test purposes"
)
await ctx.send(embeds = embeds)
So ive made a channel nuke command and this is what i have
channel = ctx.channel
channel_position = channel.position
new_channel = await channel.clone()
await channel.delete()
await new_channel.edit(position=channel_position, sync_permissions=True)
await new_channel.ctx.send("Channel Nuked")
I was wondering how to make the bot send a message into the new channel
Simply use await new_channel.send("Channel Nuked") instead of await new_channel.ctx.send("Channel Nuked").
async def on_reaction_add(reaction, user):
emoji = reaction.emoji
if emoji == "💌":
await user.channel.send("HI")
I got problem here with user.
I want to use here with ctx like ctx.channel.send.
but also it occured error how to use ctx in here?
Instead of using the on_reaction_add event, it's better in this case to use a wait_for command event. This would mean the event can only be triggered once and only when the command was invoked. However with your current event, this allows anyone to react to a message with that emoji and the bot would respond.
By using client.wait_for("reaction_add"), this would allow you to control when a user can react to the emoji. You can also add checks, this means only the user would be able to use the reactions on the message the bot sends. Other parameters can be passed, but it's up to you how you want to style it.
In the example below shows, the user can invoke the command, then is asked to react. The bot already adds these reactions, so the user would only need to react. The wait_for attribute would wait for the user to either react with the specified emojis and your command would send a message.
#client.command()
async def react(ctx):
message = await ctx.send('React to this message!')
mail = '💌'
post = '📮'
await message.add_reaction(mail)
await message.add_reaction(post)
def check(reaction, user):
return user == ctx.author and str(
reaction.emoji) in [mail, post]
member = ctx.author
while True:
try:
reaction, user = await client.wait_for("reaction_add", timeout=10.0, check=check)
if str(reaction.emoji) == mail:
await ctx.send('Hi you just received')
if str(reaction.emoji) == post:
await ctx.send('Hi you just posted...')
You need to use reaction.message.channel.send
async def on_reaction_add(reaction, user):
emoji = reaction.emoji
if str(emoji) == "💌": await reaction.message.channel.send("HI")
I'm new to discord bot making, and I'd like to have the bot add a reaction to my message that, once pressed, allows the user reacting to pick up a role. What would be the code to allow me to do this? Thank you.
This is a very well written and formatted question! In order for the bot to detect that the reaction is on a specific message, you can do many ways. The easiest way would be to be by ID, so I'm just going to do this with a simple command.
messageIDs = []
#client.event
async def on_raw_reaction_add(payload):
global messageIDs
for messageID in messageIDs:
if messageID == payload.message_id:
user = payload.member
role = "roleName"
await user.add_roles(discord.utils.get(user.guild.roles, name = role))
#client.command()
async def addMessage(ctx, messageID):
global messageIDs
emoji = "👍"
channel = ctx.message.channel
try:
msg = await channel.fetch_message(messageID)
except:
await ctx.send("Invalid Message ID!")
return
await msg.add_reaction(emoji)
messageIDs.append(messageID)
I’m trying to make a code that you can dm the bot for help, suggestions, or whatever and it will send the message in a channel. Once you get the message you can do .dm (user) (message) and then the bot will then dm the user back. I’m having some issues I’m pretty new to coding and I think my format is outdated. If someone could help that would be awesome.
#vini.event
async def on_message(message):
channel = vini.get_channel('633053538334932992')
if message.guild is None and message.author != vini.user:
await channel.send(message.content)
await vini.process_commands(message)
#vini.command(pass_context=True)
#commands.is_owner()
async def dm(ctx):
memberID = "ID OF RECIPIENT"
person = await vini.get_user_info(memberID)
await ctx.send(“WHAT TO SAY", delete_after=2)
Error:
File "main.py", line 133, in on_message
await channel.send(message.content)
AttributeError: 'NoneType' object has no attribute 'send'
If someone could help it would be greatly appreciated. Thanks!