Are you a discord freak? Don't want to open twitter and still make posts? Don't worry, we are to your rescue. Just go to omg.ac/command and make a slash command named `post` with a string option as tweet. And we are all set.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// you will have to link twitter account to be able to use it
// register the initial response
await lib.discord.interactions['@1.0.1'].responses.create({
token: `${context.params.event.token}`,
response_type: 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE',
});
let tweet = context.params.event.data.options[0].value;
// check if the tweet is more than allowed length
if (tweet.length > 280) {
await lib.discord.interactions['@1.0.1'].followups.create({
token: `${context.params.event.token}`,
content:
`β Can't post this as the size is more than the allowed limit. Reduce ` +
tweet.length -
280 +
` words or more to post it. `,
});
}
// if its okay, post it
else {
await lib.twitter.tweets['@1.1.2'].statuses.create({
status: `${tweet}`,
});
// now dm the user to tell the tweet was sent.
await lib.discord.users['@0.2.1'].dms.create({
recipient_id: `${context.params.event.member.user.id}`,
content: `Tweet was posted`,
});
}