JDA - get author of the message in GuildMessageReactionAdd / Discord - discord-jda

im trying to find out a way to get the author of the message that somebody has reacted to.
> e.getChannel().getHistory().getMessageById(e.getMessageId()).getAuthor();
this is what i've got but it returns null

Use GuildMessageReactionAddEvent#retrieveMessage:
event.retrieveMessage().queue(message -> {
... code that uses the message ...
});

Related

PowerQuery: Getting error info when it's too late to `try`?

Short Version
In PowerQuery, when the error occurs before I'm able to use try, how do I catch an error and get the reason and message strings?
Long Version
In PowerQuery (using Excel if that matters),
OleDb.DataSource(
MyConnectionString,
[Query="SELECT * FROM NonExistingTable"]
)
returns an error. Great. I want that because I'm trying to make a quick and dirty tool that grabs data from multiple tables, but some people don't have access to all tables and who knows what else will happen in the future. However, I want to handle that error so it degrades gracefully, preferably presenting an explanation to the user based on the info within the error.
Therefore, I attempted error handling with try, like so:
try OleDb.DataSource(
MyConnectionString,
[Query="SELECT * FROM NonExistingTable"]
)
and I had expected it to return something like
[
HasError = true,
Error = [
Reason = "OLE DB",
Message = "Invalid object name: 'NonExistingTable'.",
Details = ...
]
]
but instead, what's returned is
[
HasError = false,
Value = Error
]
where Error is an error object containing the information I want.
I had then tried to make a workaround with something like
let
tryRecord = try OleDb.DataSource(MyConnectionString, [Query="SELECT * FROM NonExistingTable"]),
ret = if (tryRecord[HasError]) then
// It's an error
tryRecord
else try
// If Value.Type() doesn't throw an error then tryRecord[Value] isn't an error, so return it.
(if Value.Type(tryRecord[Value]) = null then null else tryRecord)
otherwise
// tryRecord[Value] contains an error!
try error tryRecord[Value]
in
ret
but try error tryRecord[Value] is not unpacking the error object within tryRecord[Value] like I had hoped.
How do I get the reason and message strings from an error object?

How to retrieve a message link if it contains a specific string?

I tried doing something like this
ctx = message
"https://discordapp.com/channels/"+ctx.guild.id+"/"+ctx.channel.id+"/"+ctx.id
"https://discordapp.com/channels/"+guild.id+"/"+ctx.channel.id+"/"+ctx.id
Neither worked
If you're confused, Lets say if the message contains "hi" I want it to copy the message link and post it, so if someone clicks on the link it redirects them to that message
Thank you for reading.
#client.command()
async def keyword(ctx, *, word: str): # Usage: !keyword hi
messages = await ctx.channel.history(limit=200).flatten() # Get last 200 messages
for msg in messages: # Iterate through all messages.
if word in msg.content:
await ctx.send(msg.jump_url) # Send the jump link to the message containing the word.
discord.Message.jump_url
Reference:https://discordpy.readthedocs.io/en/latest/api.html?highlight=jump_url#discord.Message.jump_url

Deleting a discord message from discordgo

I am trying to delete a discord message using discordgo. Currently I have the ping pong example, however instead of writing a message I want to delete the message.
I have currently got this far:
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID || m.Author.Bot {
return
}
if m.Content == "ping" {
s.ChannelMessageDelete(m.ChannelID, m.ID)
}
}
But the implementation does not delete the message even though other code in the block will run. I am a bit of a newb to go and I don't know if there is some future error .. or something like the bot does not have the correct discord permissions?
The reason it was not posting was because the bot did not have the Manage Messages permission. This can be done by checking the Manage Messages checkbox when generating the invite link on the OAuth tab.

Testrail API Ruby add_result_for_case error

I am executing the code below as a cucumber step. The test case id is
C70. I tried a run ID and it gave the same error.
The code and error are below -
-----------------
require 'testrail-ruby'
client = TestRail::APIClient.new('https://xxxx.testrail.net')
client.user = 'xxxxxxxxxx.com'
client.password = 'xxxxxx'
r = client.send_post(
'add_result_for_case/C270',
{ :status_id => 1, :comment => 'This test worked fine!' }
)
puts r
The Error:
TestRail API returned HTTP 400 ("Field :run_id is not a valid ID.")
What am I doing wrong? I have researched this topic and have not resolved it Please advise....
I found my problem . I should have used the full Test Case ID. The ID that found when running the actual test case . The issue is resloved.
Extra suggestion.
Do not use characters other than numbers when giving the ID information. For example, when giving the case Id, it shows up as C270 in Testrail. But you have to give it as 270 in Api. In another example, let your RunId be R150. You only need to give it as 150.

Error handling for Quandl API

I'm using Quandl Ruby Client but sometimes it shows error that reason maybe when there is no code in Quandl.
Error message:
handle_api_error': (Status 404) (Quandl Error QECx02) You have
submitted an incorrect Quandl code. Please check your Quandl codes and
try again. (Quandl::NotFoundError)
My code:
data = Quandl::Dataset.get("TSE/7959").data( params: {limit:1})
I've already set api_key and api_version.
I read the library page but have no idea how to handle this error...
Does anyone have idea?
Thanks a lot!
I reolved this issue ruby's error handling.
begin
data = Quandl::Dataset.get("TSE/7959").data( params: {limit:1})
return data
rescure => e
p e
end
Thank you!

Resources