Sending message to a new channel discord.py - discord.py

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").

Related

How do I make it so this message gets sent a specific channel? (Discord.py)

I want the message to get sent to a specific channel
async def on_message_edit(before, after):
await before.channel.send(
f'{before.author} edited a message.\n'
f'Before: {before.content}\n'
f'After: {after.content}'
)
To send a message in a specific channel you need first to fetch the choosed channel by using his id by using get_channel() like this:
specificChannel = bot.get_channel(int(YOUR_CHANNEL_ID_HERE))
Then your event block should look like this:
#client.event
async def on_message_edit(before, after):
specificChannel = bot.get_channel(int(YOUR_CHANNEL_ID_HERE))
await specificChannel.send(
f'{before.author} edited a message.\n'
f'Before: {before.content}\n'
f'After: {after.content}'
)
Useful link:
get_channel()
Discord.py documentation
maybe this can help u :)
#client.event
async def on_member_join(member:Member):
if member.bot:
guild:discord.Guild = member.guild
role = guild.get_role(config.botRoleID)
channel:discord.TextChannel = guild.get_channel(YOUR_CHANNEL_ID)
await member.add_roles(role)
await channel.send(f'Set Bot role to "{member.display_name}" 😌')

Discord.py adding a role through reactions

I am using code that I found here.
But, I'm getting an error that the client object doesn't have the attribute send_message. I have tried message.channel.send but that failed as well.
#client.event
async def on_ready():
Channel = client.get_channel('YOUR_CHANNEL_ID')
Text= "YOUR_MESSAGE_HERE"
Moji = await client.send_message(Channel, Text)
await client.add_reaction(Moji, emoji='🏃')
#client.event
async def on_reaction_add(reaction, user):
Channel = client.get_channel('YOUR_CHANNEL_ID')
if reaction.message.channel.id != Channel:
return
if reaction.emoji == "🏃":
Role = discord.utils.get(user.server.roles, name="YOUR_ROLE_NAME_HERE")
await client.add_roles(user, Role)
One of the reasons why your code might not be working is because you may have your channel id stored in a string. Your code shows:
Channel = client.get_channel('YOUR CHANNEL ID')
The code above shows that your channel id is stored in a string, which it should not be. With the code above, your actual code may look like this:
Channel = client.get_channel('1234567890')
Instead you should have:
Channel = client.get_channel(1234567890)

Discord.py react to bot own messages

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

How to make a discord.py reaction role code

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)

Typing indicator for bot framework in C#

I have a bot in Bot framework. Once user responds to the bot and bot is processing it, I want to show the typing indicator to the user in the meanwhile.
It is possible in Nodejs here - https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-send-typing-indicator
But how can I implement it in C#?
You have to send an activity of type Typing.
You can do it like that:
// Send "typing" information
Activity reply = activity.CreateReply();
reply.Type = ActivityTypes.Typing;
reply.Text = null;
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
You can also create the message using context.MakeMessage if you need to instantly respond in MessageReceivedAsync of a dialog.
var typingMsg = context.MakeMessage();
typingMsg.Type = ActivityTypes.Typing;
typingMsg.Text = null;
await context.PostAsync(typingMsg);
The typing indicator is replaced by the next message sent (at least in the Bot Framework emulator). This doesn't seem to work in Slack.
Here's another approach to send a typing indicator with a bot framework in C#, JavaScript, or Python.
Try use this:
var reply = activity.CreateReply();
reply.Text = null;
reply.Type = ActivityTypes.Typing;
await context.PostAsync(reply);
For showing typing indicator while bot is processing just add in OnTurnAsync function before await base.OnTurnAsync(turnContext, cancellationToken); :
await turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing }, cancellationToken);
If V4, following lines of code can help. Keep this code at such a place so that it gets executed everytime during the dialogue flow.
IMessageActivity reply1 = innerDc.Context.Activity.CreateReply();
reply1.Type = ActivityTypes.Typing;
reply1.Text = null;
await innerDc.Context.SendActivityAsync( reply1, cancellationToken: cancellationToken);
await Task.Delay(1000);

Resources