Support removing other user's reactions

This commit is contained in:
Helloyunho 2020-12-25 13:44:42 +09:00
parent eac5d52d83
commit 540f3b1877
2 changed files with 25 additions and 7 deletions

View file

@ -135,7 +135,10 @@ export class Message extends Base {
return this.channel.addReaction(this, emoji)
}
async removeReaction(emoji: string | Emoji): Promise<void> {
return this.channel.removeReaction(this, emoji)
async removeReaction(
emoji: string | Emoji,
user?: User | Member | string
): Promise<void> {
return this.channel.removeReaction(this, emoji, user)
}
}

View file

@ -13,13 +13,16 @@ import {
CHANNEL,
CHANNEL_MESSAGE,
CHANNEL_MESSAGES,
MESSAGE_REACTION_ME
MESSAGE_REACTION_ME,
MESSAGE_REACTION_USER
} from '../types/endpoint.ts'
import { Channel } from './channel.ts'
import { Embed } from './embed.ts'
import { Emoji } from './emoji.ts'
import { Guild } from './guild.ts'
import { Member } from './member.ts'
import { Message } from './message.ts'
import { User } from './user.ts'
export type AllMessageOptions = MessageOption | Embed
@ -147,7 +150,8 @@ export class TextChannel extends Channel {
async removeReaction(
message: Message | string,
emoji: Emoji | string
emoji: Emoji | string,
user?: User | Member | string
): Promise<void> {
if (emoji instanceof Emoji) {
emoji = emoji.getEmojiString
@ -155,12 +159,23 @@ export class TextChannel extends Channel {
if (message instanceof Message) {
message = message.id
}
if (user !== undefined) {
if (typeof user !== 'string') {
user = user.id
}
}
const encodedEmoji = encodeURI(emoji)
if (user === undefined) {
await this.client.rest.delete(
MESSAGE_REACTION_ME(this.id, message, encodedEmoji)
)
} else {
await this.client.rest.delete(
MESSAGE_REACTION_USER(this.id, message, encodedEmoji, user)
)
}
}
}