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 class
Webhook.Type
Represents the various types of webhooks.
-
Constructor Summary
Constructors Constructor Description Webhook(GatewayDiscordClient gateway, discord4j.discordjson.json.WebhookData data)
Constructs aWebhook
with an associatedGatewayDiscordClient
and 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>
deleteWithToken()
Requests to delete this webhook.discord4j.core.spec.WebhookEditMono
edit()
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.WebhookEditWithTokenMono
editWithToken()
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 specsboolean
equals(Object obj)
discord4j.core.spec.WebhookExecuteMono
execute()
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.Snowflake
getChannelId()
Gets the ID of the channel this webhook is associated to.GatewayDiscordClient
getClient()
Returns theGatewayDiscordClient
that created this object.Optional<User>
getCreator()
Requests to retrieve the user this webhook was created by, if present.discord4j.discordjson.json.WebhookData
getData()
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.Snowflake
getGuildId()
Gets the ID of the guild this webhook is associated to.Snowflake
getId()
Gets the Snowflake that uniquely identifies this entity.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.Type
getType()
Gets the type of the webhook.int
hashCode()
String
toString()
-
-
-
Constructor Detail
-
Webhook
public Webhook(GatewayDiscordClient gateway, discord4j.discordjson.json.WebhookData data)
Constructs aWebhook
with an associatedGatewayDiscordClient
and Discord data.- Parameters:
gateway
- TheGatewayDiscordClient
associated 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:DiscordObject
Returns theGatewayDiscordClient
that created this object. Methods in it are exclusively based on the entity cache orStore
in use. Refer to callinggetClient().rest()
to access aDiscordClient
that is capable of requesting entities directly from the REST API.- Specified by:
getClient
in interfaceDiscordObject
- Returns:
- The
GatewayDiscordClient
associated to this object.
-
getId
public Snowflake getId()
Description copied from interface:Entity
Gets 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.INCOMING
webhooks.- 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
Mono
where, 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
Mono
where, 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
Mono
where, 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
- AConsumer
that provides a "blank"LegacyWebhookEditSpec
to be operated on.- Returns:
- A
Mono
where, 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 thewithXxx
methods of the returnedWebhookEditMono
. Requires the MANAGE_WEBHOOKS permission.- Returns:
- A
WebhookEditMono
where, 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
- AConsumer
that provides a "blank"LegacyWebhookEditWithTokenSpec
to be operated on.- Returns:
- A
Mono
where, 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 thewithXxx
methods of the returnedWebhookEditWithTokenMono
. Does not require the MANAGE_WEBHOOKS permission.- Returns:
- A
WebhookEditWithTokenMono
where, 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
- AConsumer
that provides a "blank"LegacyWebhookExecuteSpec
to be operated on.- Returns:
- A
Mono
where, 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 thewithXxx
methods of the returnedWebhookExecuteMono
.- Returns:
- A
WebhookExecuteMono
where, upon successful webhook execution, emits a Message ifwithWaitForMessage(true)
. If the message fails to save, an error is emitted through theWebhookExecuteMono
only 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
Mono
where, 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
- AConsumer
that provides a "blank"LegacyWebhookExecuteSpec
to be operated on.- Returns:
- A
Mono
where, upon successful webhook execution, emits a Message ifwait = true
. If the message fails to save, an error is emitted through theMono
only 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
Mono
where, upon successful webhook execution, emits a Message ifwait = true
. If the message fails to save, an error is emitted through theMono
only 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
- AConsumer
that provides a "blank"LegacyWebhookExecuteSpec
to be operated on.- Returns:
- A
Mono
where, 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
Mono
where, upon successful webhook execution, emits a Message. If the message fails to save, an error is emitted through theMono
.
-
-