Package discord4j.core.object.entity
Class Webhook
- java.lang.Object
-
- discord4j.core.object.entity.Webhook
-
- All Implemented Interfaces:
DiscordObject,Entity
public final class Webhook extends Object implements Entity
A Discord webhook.- See Also:
- Webhook Resource
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWebhook.TypeRepresents the various types of webhooks.
-
Constructor Summary
Constructors Constructor Description Webhook(GatewayDiscordClient gateway, discord4j.discordjson.json.WebhookData data)Constructs aWebhookwith an associatedGatewayDiscordClientand Discord data.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Mono<Void>delete()Requests to delete this webhook.Mono<Void>delete(String reason)Requests to delete this webhook while optionally specifying a reason.Mono<Void>deleteMessage(Snowflake messageId)Executes this webhook to delete a message.Mono<Void>deleteWithToken()Requests to delete this webhook.discord4j.core.spec.WebhookEditMonoedit()Requests to edit this webhook.Mono<Webhook>edit(discord4j.core.spec.WebhookEditSpec spec)Requests to edit this webhook.Mono<Webhook>edit(Consumer<? super LegacyWebhookEditSpec> spec)Deprecated.useedit(WebhookEditSpec)oredit()which offer an immutable approach to build specsdiscord4j.core.spec.WebhookMessageEditMonoeditMessage(Snowflake messageId)Executes this webhook to edit a message.Mono<Message>editMessage(Snowflake messageId, discord4j.core.spec.WebhookMessageEditSpec spec)Executes this webhook to edit a message.discord4j.core.spec.WebhookEditWithTokenMonoeditWithToken()Requests to edit this webhook.Mono<Webhook>editWithToken(discord4j.core.spec.WebhookEditWithTokenSpec spec)Requests to edit this webhook.Mono<Webhook>editWithToken(Consumer<? super LegacyWebhookEditWithTokenSpec> spec)Deprecated.useeditWithToken(WebhookEditWithTokenSpec)oreditWithToken()which offer an immutable approach to build specsbooleanequals(Object obj)discord4j.core.spec.WebhookExecuteMonoexecute()Executes this webhook.Mono<Message>execute(boolean wait, discord4j.core.spec.WebhookExecuteSpec spec)Executes this webhook.Mono<Message>execute(boolean wait, Consumer<? super LegacyWebhookExecuteSpec> spec)Deprecated.useexecute(boolean, WebhookExecuteSpec)which offers an immutable approach to build specsMono<Void>execute(discord4j.core.spec.WebhookExecuteSpec spec)Executes this webhook without waiting for a confirmation that a message was created.Mono<Void>execute(Consumer<? super LegacyWebhookExecuteSpec> spec)Deprecated.useexecute(WebhookExecuteSpec)orexecute()which offer an immutable approach to build specsMono<Message>executeAndWait(discord4j.core.spec.WebhookExecuteSpec spec)Executes this webhook and waits for server confirmation for the message to save.Mono<Message>executeAndWait(Consumer<? super LegacyWebhookExecuteSpec> spec)Deprecated.useexecuteAndWait(WebhookExecuteSpec)which offers an immutable approach to build specsOptional<Snowflake>getApplicationId()Gets the bot/OAuth2 application ID that created this webhook.Optional<String>getAvatar()Gets the avatar of this webhook, if present.Mono<GuildMessageChannel>getChannel()Requests to retrieve the channel this webhook is associated to.Mono<GuildMessageChannel>getChannel(EntityRetrievalStrategy retrievalStrategy)Requests to retrieve the channel this webhook is associated to, using the given retrieval strategy.SnowflakegetChannelId()Gets the ID of the channel this webhook is associated to.GatewayDiscordClientgetClient()Returns theGatewayDiscordClientthat created this object.Optional<User>getCreator()Requests to retrieve the user this webhook was created by, if present.discord4j.discordjson.json.WebhookDatagetData()Gets the data of the webhook.Mono<Guild>getGuild()Requests to retrieve the guild this webhook is associated to.Mono<Guild>getGuild(EntityRetrievalStrategy retrievalStrategy)Requests to retrieve the guild this webhook is associated to, using the given retrieval strategy.SnowflakegetGuildId()Gets the ID of the guild this webhook is associated to.SnowflakegetId()Gets the Snowflake that uniquely identifies this entity.Mono<Message>getMessage(Snowflake messageId)Executes this webhook to get a message.Optional<String>getName()Gets the default name of the webhook.Optional<Snowflake>getSourceChannelId()Gets the id of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.Optional<String>getSourceChannelName()Gets the name of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.Optional<Snowflake>getSourceGuildId()Gets the guild id of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.Optional<String>getSourceGuildName()Gets the guild name of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.Optional<String>getToken()Gets the secure token of this webhook.Webhook.TypegetType()Gets the type of the webhook.inthashCode()StringtoString()
-
-
-
Constructor Detail
-
Webhook
public Webhook(GatewayDiscordClient gateway, discord4j.discordjson.json.WebhookData data)
Constructs aWebhookwith an associatedGatewayDiscordClientand Discord data.- Parameters:
gateway- TheGatewayDiscordClientassociated to this object, must be non-null.data- The raw data as represented by Discord, must be non-null.
-
-
Method Detail
-
getClient
public GatewayDiscordClient getClient()
Description copied from interface:DiscordObjectReturns theGatewayDiscordClientthat created this object. Methods in it are exclusively based on the entity cache orStorein use. Refer to callinggetClient().rest()to access aDiscordClientthat is capable of requesting entities directly from the REST API.- Specified by:
getClientin interfaceDiscordObject- Returns:
- The
GatewayDiscordClientassociated to this object.
-
getId
public Snowflake getId()
Description copied from interface:EntityGets the Snowflake that uniquely identifies this entity.
-
getData
public discord4j.discordjson.json.WebhookData getData()
Gets the data of the webhook.- Returns:
- The data of the webhook.
-
getType
public Webhook.Type getType()
Gets the type of the webhook.- Returns:
- The type of the webhook.
-
getGuildId
public Snowflake getGuildId()
Gets the ID of the guild this webhook is associated to.- Returns:
- The ID of the guild this webhook is associated to.
-
getGuild
public Mono<Guild> getGuild()
Requests to retrieve the guild this webhook is associated to.
-
getGuild
public Mono<Guild> getGuild(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the guild this webhook is associated to, using the given retrieval strategy.
-
getChannelId
public Snowflake getChannelId()
Gets the ID of the channel this webhook is associated to.- Returns:
- The ID of the channel this webhook is associated to.
-
getChannel
public Mono<GuildMessageChannel> getChannel()
Requests to retrieve the channel this webhook is associated to.
-
getChannel
public Mono<GuildMessageChannel> getChannel(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the channel this webhook is associated to, using the given retrieval strategy.
-
getCreator
public Optional<User> getCreator()
Requests to retrieve the user this webhook was created by, if present. Returns no creator if the webhook was retrieved using a token.
-
getName
public Optional<String> getName()
Gets the default name of the webhook.- Returns:
- The default name of the webhook.
-
getAvatar
public Optional<String> getAvatar()
Gets the avatar of this webhook, if present.- Returns:
- The avatar of this webhook, if present.
-
getToken
public Optional<String> getToken()
Gets the secure token of this webhook. The token is present forWebhook.Type.INCOMINGwebhooks.- Returns:
- The secure token of this webhook.
-
getApplicationId
public Optional<Snowflake> getApplicationId()
Gets the bot/OAuth2 application ID that created this webhook.- Returns:
- The bot/OAuth2 application ID that created this webhook.
-
getSourceGuildId
public Optional<Snowflake> getSourceGuildId()
Gets the guild id of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.- Returns:
- The guild id of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.
-
getSourceGuildName
public Optional<String> getSourceGuildName()
Gets the guild name of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.- Returns:
- The guild name of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.
-
getSourceChannelId
public Optional<Snowflake> getSourceChannelId()
Gets the id of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.- Returns:
- The id of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.
-
getSourceChannelName
public Optional<String> getSourceChannelName()
Gets the name of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.- Returns:
- The name of the channel that this webhook is following (returned for Channel Follower Webhooks), if present.
-
delete
public Mono<Void> delete()
Requests to delete this webhook. Requires the MANAGE_WEBHOOKS permission.- Returns:
- A
Monowhere, upon successful completion, emits nothing; indicating the webhook has been deleted. If an error is received, it is emitted through theMono.
-
delete
public Mono<Void> delete(@Nullable String reason)
Requests to delete this webhook while optionally specifying a reason. Requires the MANAGE_WEBHOOKS permission.- Parameters:
reason- The reason, if present.- Returns:
- A
Monowhere, upon successful completion, emits nothing; indicating the webhook has been deleted. If an error is received, it is emitted through theMono.
-
deleteWithToken
public Mono<Void> deleteWithToken()
Requests to delete this webhook.- Returns:
- A
Monowhere, upon successful completion, emits nothing; indicating the webhook has been deleted. If an error is received, it is emitted through theMono.
-
edit
@Deprecated public Mono<Webhook> edit(Consumer<? super LegacyWebhookEditSpec> spec)
Deprecated.useedit(WebhookEditSpec)oredit()which offer an immutable approach to build specsRequests to edit this webhook. Requires the MANAGE_WEBHOOKS permission.- Parameters:
spec- AConsumerthat provides a "blank"LegacyWebhookEditSpecto be operated on.- Returns:
- A
Monowhere, upon successful completion, emits the editedWebhook. If an error is received, it is emitted through theMono.
-
edit
public discord4j.core.spec.WebhookEditMono edit()
Requests to edit this webhook. Properties specifying how to edit this webhook can be set via thewithXxxmethods of the returnedWebhookEditMono. Requires the MANAGE_WEBHOOKS permission.- Returns:
- A
WebhookEditMonowhere, upon successful completion, emits the editedWebhook. If an error is received, it is emitted through theWebhookEditMono.
-
edit
public Mono<Webhook> edit(discord4j.core.spec.WebhookEditSpec spec)
Requests to edit this webhook. Requires the MANAGE_WEBHOOKS permission.
-
editWithToken
@Deprecated public Mono<Webhook> editWithToken(Consumer<? super LegacyWebhookEditWithTokenSpec> spec)
Deprecated.useeditWithToken(WebhookEditWithTokenSpec)oreditWithToken()which offer an immutable approach to build specsRequests to edit this webhook. Does not require the MANAGE_WEBHOOKS permission.- Parameters:
spec- AConsumerthat provides a "blank"LegacyWebhookEditWithTokenSpecto be operated on.- Returns:
- A
Monowhere, upon successful completion, emits the editedWebhook. If an error is received, it is emitted through theMono.
-
editWithToken
public discord4j.core.spec.WebhookEditWithTokenMono editWithToken()
Requests to edit this webhook. Properties specifying how to edit this webhook can be set via thewithXxxmethods of the returnedWebhookEditWithTokenMono. Does not require the MANAGE_WEBHOOKS permission.- Returns:
- A
WebhookEditWithTokenMonowhere, upon successful completion, emits the editedWebhook. If an error is received, it is emitted through theWebhookEditWithTokenMono.
-
editWithToken
public Mono<Webhook> editWithToken(discord4j.core.spec.WebhookEditWithTokenSpec spec)
Requests to edit this webhook. Does not require the MANAGE_WEBHOOKS permission.
-
execute
@Deprecated public Mono<Void> execute(Consumer<? super LegacyWebhookExecuteSpec> spec)
Deprecated.useexecute(WebhookExecuteSpec)orexecute()which offer an immutable approach to build specsExecutes this webhook without waiting for a confirmation that a message was created.- Parameters:
spec- AConsumerthat provides a "blank"LegacyWebhookExecuteSpecto be operated on.- Returns:
- A
Monowhere, upon successful webhook execution, completes. If the message fails to save, an error IS NOT emitted through theMono.
-
execute
public discord4j.core.spec.WebhookExecuteMono execute()
Executes this webhook. Properties specifying how to execute this webhook, including whether to wait for confirmation that the message was created, can be set via thewithXxxmethods of the returnedWebhookExecuteMono.- Returns:
- A
WebhookExecuteMonowhere, upon successful webhook execution, emits a Message ifwithWaitForMessage(true). If the message fails to save, an error is emitted through theWebhookExecuteMonoonly ifwithWaitForMessage(true).
-
execute
public Mono<Void> execute(discord4j.core.spec.WebhookExecuteSpec spec)
Executes this webhook without waiting for a confirmation that a message was created.- Parameters:
spec- an immutable object that specifies how to execute this webhook- Returns:
- A
Monowhere, upon successful webhook execution, completes. If the message fails to save, an error IS NOT emitted through theMono.
-
execute
@Deprecated public Mono<Message> execute(boolean wait, Consumer<? super LegacyWebhookExecuteSpec> spec)
Deprecated.useexecute(boolean, WebhookExecuteSpec)which offers an immutable approach to build specsExecutes this webhook.- Parameters:
wait- True to specify to wait for server confirmation that the message was saved or there was an error saving the message.spec- AConsumerthat provides a "blank"LegacyWebhookExecuteSpecto be operated on.- Returns:
- A
Monowhere, upon successful webhook execution, emits a Message ifwait = true. If the message fails to save, an error is emitted through theMonoonly ifwait = true.
-
execute
public Mono<Message> execute(boolean wait, discord4j.core.spec.WebhookExecuteSpec spec)
Executes this webhook.- Parameters:
wait- True to specify to wait for server confirmation that the message was saved or there was an error saving the message.spec- an immutable object that specifies how to execute this webhook- Returns:
- A
Monowhere, upon successful webhook execution, emits a Message ifwait = true. If the message fails to save, an error is emitted through theMonoonly ifwait = true.
-
executeAndWait
@Deprecated public Mono<Message> executeAndWait(Consumer<? super LegacyWebhookExecuteSpec> spec)
Deprecated.useexecuteAndWait(WebhookExecuteSpec)which offers an immutable approach to build specsExecutes this webhook and waits for server confirmation for the message to save.- Parameters:
spec- AConsumerthat provides a "blank"LegacyWebhookExecuteSpecto be operated on.- Returns:
- A
Monowhere, upon successful webhook execution, emits a Message. If the message fails to save, an error is emitted through theMono.
-
executeAndWait
public Mono<Message> executeAndWait(discord4j.core.spec.WebhookExecuteSpec spec)
Executes this webhook and waits for server confirmation for the message to save.- Parameters:
spec- an immutable object that specifies how to execute this webhook- Returns:
- A
Monowhere, upon successful webhook execution, emits a Message. If the message fails to save, an error is emitted through theMono.
-
getMessage
public Mono<Message> getMessage(Snowflake messageId)
Executes this webhook to get a message.- Parameters:
messageId- The ID of the message to get- Returns:
- A
Monowhere, upon successful webhook execution, emits a Message. If the message get fails, an error is emitted through theMono.
-
editMessage
public discord4j.core.spec.WebhookMessageEditMono editMessage(Snowflake messageId)
Executes this webhook to edit a message. Properties specifying how to execute this webhook, including the ID of the message being edited, can be set via thewithXxxmethods of the returnedWebhookMessageEditMono.- Parameters:
messageId- The ID of the message to edit- Returns:
- A
WebhookMessageEditMonowhere, upon successful webhook execution, emits a Message. If the message edit fails, an error is emitted through theWebhookMessageEditMono.
-
editMessage
public Mono<Message> editMessage(Snowflake messageId, discord4j.core.spec.WebhookMessageEditSpec spec)
Executes this webhook to edit a message.- Parameters:
messageId- The ID of the message to editspec- an immutable object that specifies how to edit the message- Returns:
- A
Monowhere, upon successful webhook execution, emits a Message. If the message edit fails, an error is emitted through theMono.
-
deleteMessage
public Mono<Void> deleteMessage(Snowflake messageId)
Executes this webhook to delete a message.- Parameters:
messageId- The ID of the message to delete- Returns:
- A
Monowhere, upon successful webhook execution, emits nothing; indicating the message has been deleted. If the message delete fails, an error is emitted through theMono.
-
-