add method for check discord join and role
This commit is contained in:
parent
951122c1a7
commit
49c02ca3d3
@ -7,8 +7,8 @@ const DISCORD_API_HOST = 'https://discord.com/api/v10'
|
||||
* DISCROD_GUILD_ID
|
||||
* DISCORD_BOT_TOKEN
|
||||
*/
|
||||
export async function getGuildMember(uid: string) {
|
||||
const url = `${DISCORD_API_HOST}/guilds/${process.env.DISCROD_GUILD_ID}/members/${uid}`
|
||||
export async function getGuildMember(guid: string, uid: string) {
|
||||
const url = `${DISCORD_API_HOST}/guilds/${guid}/members/${uid}`
|
||||
const token = process.env.DISCORD_BOT_TOKEN
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
@ -24,9 +24,9 @@ export async function getGuildMember(uid: string) {
|
||||
* @param uid
|
||||
* @returns
|
||||
*/
|
||||
export async function checkJoinGuld(uid: string) {
|
||||
export async function checkJoinGuld(guid: string, uid: string) {
|
||||
try {
|
||||
const res = await getGuildMember(uid)
|
||||
const res = await getGuildMember(guid, uid)
|
||||
/**
|
||||
* if user not in guild, res will be:
|
||||
* {
|
||||
@ -48,9 +48,9 @@ export async function checkJoinGuld(uid: string) {
|
||||
* @param roleId
|
||||
* @returns
|
||||
*/
|
||||
export async function checkGotRole(uid: string, roleId: string) {
|
||||
export async function checkGotRole(guid: string, uid: string, roleId: string) {
|
||||
try {
|
||||
const res = await getGuildMember(uid)
|
||||
const res = await getGuildMember(guid, uid)
|
||||
if (res.code === 10013) {
|
||||
return false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user