Get the time when an interaction was invoked (pycord) - discord

Without slash commands, you could use the command's context the time when the command was sent: ctx.message.created_at
You could use this property to timestamp embeds, like this:
Is there any way to replicate this with slash commands' interactions?

From what I could find in the discord.py and pycord docs, I believe that using interaction.message.created_at instead of ctx.message.created_at should solve your problem

Related

Nextcord: I want to mention the sender of the slash command I made. How would I go about that?

I'm trying to make this command notify my admins of a bot test and need it to mention the user who called the command. How would I go about that? I don't fully understand how to get that information with slash commands.
#client.slash_command(name= "test", description="(For Deputies or Leader only) Checks the operational state of the client.", guild_ids=[806043206030589952])
#has_any_role(leader_id, deputy_id)
async def test(interaction:Interaction):
bot_log = channel_up(940125176723554394)
await bot_log.send(f'<#&806045254834847776>,{} has started diagnostics for the bot. Please ignore any possible disturbances for the next minute or so.')
Thanks in advance for the advice, it's the first discord bot I've ever created.
EDIT:
In documentation, I found the solution. I have to use interaction.user.mention to get it to mention the user who sent the command. Or at least in theory, I'm dealing with a different issue now. Hopefully this helps people who also were as confused as me out.
You can use the interaction.user.name function with an # at the beginning.
The code should look something like this:
await interaction.response.send_message("#"+str(interaction.user.name))

Discord.py adding reaction to webhook.send message

I am able to send messages to my discord channel via webhook very easily, however, when trying to add reactions to the messages it's very difficult, considering my programming is still trivial.
The code line I have right now is:
data_count=1
webhook.send(content=discord.Reaction(message="test", data=data_count, emoji="đź‘Ť"), file=discord.File("american_eagle_excited.gif"), embed=discord.Embed(title="Sample Embed", description="This is the description"))
Everything, when I break down the parameters I can get to work besides the discord.Reaction class. I feel like I am missing something very easily and after trying to read through the class requirements I had to finally make my way to StackOverflow.
To add a reaction you need the discord.Message instance which is returned by the webhook.send method, you then add the reaction with message.add_reaction
message = webhook.send("test", wait=True, ...) # `wait=True` is really important, if we don't set this the bot will not wait for the message to be returned
await message.add_reaction("đź‘Ť")

Custom status using discord.py rewrite

This is my code
activity=discord.Game(name="Padamine", type=1)
Don’t worry, I put it in a #bot.event function. The problem is that my bot don’t put the custom status in his status. Can you help me?
Use change_presence() method to change bot status:
await bot.change_presence(activity=discord.Game("Padamine"))
If it's a static status (a status that won't change), it is recommended to use the activity keyword argument inside the bot constructor. If you want to make a dynamic status (a status that changes every now and then), use #tasks.loop of discord.ext.tasks (you can find more about tasks here)
# depending on what you name your variable, client/bot
client/bot = commands.Bot(command_prefix="yourprefix", activity=discord.Game("Padamine")) # removed type because there is no such key word argument
Also, it is recommended to not use await bot.change_presence() inside your on_ready event, I am mentioning this because many people do it and it's not good:
Discord has a high chance to completely disconnect you during the READY or GUILD_CREATE events (1006 close code) and there is nothing you can do to prevent it. As noted in the docs, on_ready is also triggered multiple times, not just once.
Basically: don't do anything in on_ready. (except printing that it came online obviously)

How to respond to a user interaction (slash command) without sending a message

I know there is an InteractionResponseType 2, but it is deprecated, according to the docs. Is there anyway I can respond to a slash command interaction without a message?
Looks like Type 5 did the trick for me.

Why is my kick command not working? (discord.js)

I've tried using a command handler and the other commands work fine. It's just the kick command that doesn't, can anyone help? https://sourceb.in/8d4f78e43a is the code, thanks!
Since the code is pretty small, you should post it on SO instead of an external link, for archiving for the future and some other reasons you can look up
Also you should mention if you get any error logs, in this case I don't think you would have
The issue is let member = message.guild.members.cache.get(args);
You are passing in an the array args, not a string (which <Collection>.get() requires, you probably meant args[1]:
let member = message.guild.members.cache.get(args[1]);

Resources