Got a cool example to share? Get listed here! Submit it now.

useChainlinkFunctions()

Collection of community submitted examples for Chainlink Functions

Get inspired from quick examples

Chainlink Functions, a new self-service platform that allows anyone to write serverless code to fetch any data from any API and run custom compute on Chainlink's network. Learn from examples created by the community or contribute your own!
Learn more about Chainlink Functions

Fetch Discord Upvote Data

Submitted by:
Sam Demaree
This function retrieves the number of upvotes a Discord member has received in the past 24 hours. *Note: ChatGPT was used to demonstrate that non-developers can also participate.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // This function retrieves the number of upvotes a Discord member has received in the past 24 hours using the Discord API. const getDiscordUpvotes = async (memberId, apiKey, guildId, channelId, timeRangeMs) => { const endpoint = 'https://discord.com/api/v9' const timeRangeSec = Math.round(timeRangeMs / 1000) const time24HoursAgo = Math.round((Date.now() - timeRangeMs) / 1000) const headers = { 'Authorization': `Bot ${apiKey}`, 'Content-Type': 'application/json' } const config = { method: 'GET', headers: headers, url: `${endpoint}/guilds/${guildId}/audit-logs?limit=100&user_id=${memberId}&before=${time24HoursAgo}&action_type=MESSAGE_DELETE` } const response = await Functions.makeHttpRequest(config) if (response.error) { throw new Error(response.response.data.message) } const auditLogs = response.data.audit_log_entries let upvotes = 0 for (let i = 0; i < auditLogs.length; i++) { const log = auditLogs[i] if (log.action_type === 72 && log.target_id === channelId && log.created_at >= time24HoursAgo - timeRangeSec) { upvotes++ } } return Functions.encodeUint256(upvotes) }