Giovanni Giovanni
DIAdiscord.js - Imagine an app
•Created by Giovanni Giovanni on 12/12/2023 in #djs-questions
Update Guild
that guild object is exactly the same as in the documentation
16 replies
DIAdiscord.js - Imagine an app
•Created by Giovanni Giovanni on 12/12/2023 in #djs-questions
Update Guild
i am importing discord js events
16 replies
DIAdiscord.js - Imagine an app
•Created by Giovanni Giovanni on 12/12/2023 in #djs-questions
Update Guild
so i have an idea my state is late for 1 step
16 replies
DIAdiscord.js - Imagine an app
•Created by Giovanni Giovanni on 12/12/2023 in #djs-questions
Update Guild
and the method is executed on Events.GuildUpdate
16 replies
DIAdiscord.js - Imagine an app
•Created by Giovanni Giovanni on 12/12/2023 in #djs-questions
Update Guild
guild is fetched as a parameter of the method
16 replies
DIAdiscord.js - Imagine an app
•Created by Giovanni Giovanni on 12/12/2023 in #djs-questions
Update Guild
this is inside my try block logger.trace('Trying to retrieve cached M2M Token...');
const m2mToken = await cache.get(CACHE_KEYS.M2M_TOKEN);
let freshM2MToken;
if (!m2mToken) {
logger.trace('No M2M Token in the cache, fetching a new one...');
freshM2MToken = await fetchM2MToken();
cache.set(CACHE_KEYS.M2M_TOKEN, freshM2MToken);
}
logger.trace(
'Attempting to ping LP API to fetch guild's LP discord server...'
);
const response = await axios.get(
${letsPlayApiPath}/connection/discord/${guild.guild.id}
,
{
headers: {
Authorization: Bearer ${m2mToken ?? freshM2MToken}
,
},
}
);
if (!response.data) {
logger.trace('Couldn't fetch guild's LP discord server from LP API.');
return;
}
const { name, iconUrl } = response.data;
logger.trace({ name, iconUrl });
if (name !== guild.guild.name || iconUrl !== guild.iconUrl) {
logger.trace(
'Attempting to ping LP API to update discord server name or icon url...'
);
await axios.patch(
${letsPlayApiPath}/connection/discord/${guild.id}
,
{
name: guild.guild.name,
iconUrl: guild.iconUrl,
},
{
headers: {
Authorization: Bearer ${m2mToken ?? freshM2MToken}
,
},
}
);
logger.trace('Successfully updated discord server name or icon url.');
} else {
logger.trace('Discord server name and icon url are not changed.');
}16 replies