Skip to content

Commit

Permalink
Fixes missing send on discord context
Browse files Browse the repository at this point in the history
Co-authored-by: Gerard <[email protected]>
  • Loading branch information
mikecmart and gdomenech98 committed Nov 12, 2024
1 parent 35ad726 commit 69af5a5
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/protolib/src/bundles/discord/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ type connectProps = {
apiKey?: string
}

const send = async ({ channel, message, onSend }: { channel: any, message: string, onSend?: Function }) => {
if (channel && typeof channel === 'string') { // Checks that provided channel is channelId instead of channel object
try {
channel = await client.channels.fetch(channel); // Fetch channel object given channelId ('channel')
} catch (err) {
console.error("Error fetching channel: ", err);
}
}
channel.send(message)
if (onSend) onSend()
}

export const discord = {
connect: async ({ onMessage, onConnect, onDisconnect, onError, apiKey }: connectProps) => {
const key = await getToken(apiKey)
Expand All @@ -52,17 +64,7 @@ export const discord = {
console.error("Bot initialization error", err)
}
},
send: async ({ channel, message, onSend }: { channel: any, message: string, onSend?: Function }) => {
if (channel && typeof channel === 'string') { // Checks that provided channel is channelId instead of channel object
try {
channel = await client.channels.fetch(channel); // Fetch channel object given channelId ('channel')
} catch (err) {
console.error("Error fetching channel: ", err);
}
}
channel.send(message)
if (onSend) onSend()
},
send,
response: async ({ message, response, onSend }: { message: any, response: string, onSend?: Function }) => {
return send({ channel: message.channel, message: response, onSend })
},
Expand Down

0 comments on commit 69af5a5

Please sign in to comment.