Skip to content

Commit

Permalink
feat(unpin-msg): Added message.unpin() method to unpin messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuyy committed May 23, 2020
1 parent b09638d commit ebc34a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/client/rest/RestAPIHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export default class RestAPIHandler {
return fetch(`${Constants.API}/${ENDPOINTS.CHANNELS}/${channelId}/${ENDPOINTS.PINS}/${messageId}`, { method: 'PUT', headers });
}

async unpinMessage(channelId: string, messageId: string): Promise<any> {
return fetch(`${Constants.API}/${ENDPOINTS.CHANNELS}/${channelId}/${ENDPOINTS.PINS}/${messageId}`, { method: 'DELETE', headers });
}

async createMessage(options: MessageOptions, id: string) {
const response = await fetch(
`${Constants.API}/${ENDPOINTS.CHANNELS}/${id}/${ENDPOINTS.MESSAGES}`,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ client.on("message", async (message: Message) => {
await message.fetch();
} else if (message.content === '?pin') {
await message.pin();
} else if (message.content === '?unpin') {
await message.unpin();
}
});

Expand Down
5 changes: 5 additions & 0 deletions src/models/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export class Message {
await this.channel.client.rest.pinMessage(this.channel.id, this.id);
return this;
}

public async unpin(): Promise<Message> {
await this.channel.client.rest.unpinMessage(this.channel.id, this.id);
return this;
}
}


Expand Down

0 comments on commit ebc34a5

Please sign in to comment.