> For the complete documentation index, see [llms.txt](https://legacy.docs.touchguild.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://legacy.docs.touchguild.com/documentation/select-version/v.0.1.7/examples/snipe-and-editsnipe.md).

# Snipe & editsnipe

### Usage:

* !snipe (snipes the last deleted message of the current channel)
* !editsnipe (editsnipes the last edited message of the current channel)
* !snipe CHANNELID (same as snipe but custom channel id)
* !editsnipe CHANNELID (same as editsnipe but custom channel id)

```typescript
// Importing TouchGuild.
import * as TouchGuild from 'touchguild';

// Creating client & connecting.
const client = new TouchGuild.Client({token: 'token here', REST: true});
client.connect();

// Declaring deleted & edited message maps.
var lastDeletedMessage = new Map();
var lastEditedMessage = new Map();

// Standard command handler, message detection.
client.on('messageCreate', (message)=> {
    let args = message.content?.split(' '); // array of args.

    message.content = message.content?.toLowerCase();

    if (message.content?.startsWith('!snipe') && args?.[1]){
        if (!lastDeletedMessage.has(args?.[1])) return message.createMessage({content: `No deleted message detected for: *${args?.[1]}*`});
        return message.createMessage({content: `Last deleted message content: ${lastDeletedMessage.get(args?.[1])}`});
    }else if (message.content == '!snipe'){
        if (!lastDeletedMessage.has(message.channelID)) return message.createMessage({content: 'No deleted message detected for the moment.'});
        return message.createMessage({content: `Last deleted message content: ${lastDeletedMessage.get(message.channelID)}`});
    }

    if (message.content?.startsWith('!editsnipe') && args?.[1]){
        if (!lastEditedMessage.has(args?.[1])) return message.createMessage({content: `No edited message detected for: *${args?.[1]}*`});
        return message.createMessage({content: `Last edited message content: ${lastEditedMessage.get(args?.[1])}`});
    }else if (message.content == '!editsnipe'){
        if (!lastEditedMessage.has(message.channelID)) return message.createMessage({content: 'No edited message detected for the moment.'});
        return message.createMessage({content: `Last edited message content: ${lastEditedMessage.get(message.channelID)}`});
    }
})

// Detect when message is updated/deleted & save their content.
client.on('messageUpdate', (message)=> {
    if (!message.oldContent) return; // return if message oldContent not cached.
    lastEditedMessage.set(message.channelID, message.oldContent);
})

client.on('messageDelete', (message)=> {
    if (!message.oldContent) return; // return if message oldContent not cached.
    lastDeletedMessage.set(message.channelID, message.oldContent);
})
```

{% hint style="info" %}
Examples that are in the Nightly category may not work on stable builds, if it's the case, wait for the next stable build to release.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://legacy.docs.touchguild.com/documentation/select-version/v.0.1.7/examples/snipe-and-editsnipe.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
