I’m trying to rename a Discord Channel using the Discord → Use any Discord API in Node.js step, but I keep getting a 401 Unauthorized error.
I successfully connected my Discord account, the Pipedream discord bot joined my server as an administrator, and it is able to send messages in channels using the Discord → Send Message step earlier in the workflow.
I also successfully tested the default code in the Use any Discord API in Node.js step, so I don’t think it’s having trouble connecting to Discord or authorizing.
import { axios } from "@pipedream/platform"
export default defineComponent({
props: {
discord: {
type: "app",
app: "discord",
}
},
async run({steps, $}) {
return await axios($, {
url: `https://discord.com/api/users/@me`,
headers: {
Authorization: `Bearer ${this.discord.$auth.oauth_access_token}`,
"accept": `application/json`,
},
})
},
})
Here is the code I am trying to test unsuccessfully because it is returning a 401 Unauthorized error:
import { axios } from "@pipedream/platform"
export default defineComponent({
props: {
discord: {
type: "app",
app: "discord",
}
},
async run({ steps, $ }) {
// Get the current day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
const currentDayIndex = new Date().getDay();
// Define an array of channel names for each day of the week
const channelNames = [
"Sunday Channel",
"Monday Channel",
"Tuesday Channel",
"Wednesday Channel",
"Thursday Channel",
"Friday Channel",
"Saturday Channel",
];
// Use the current day index to get the corresponding channel name
const newChannelName = channelNames[currentDayIndex];
// Replace with the actual channel ID
const channelId = "1192532661877604462";
// Update the channel name using the Discord API
const response = await axios($, {
method: "patch",
url: `https://discord.com/api/channels/${channelId}`,
headers: {
Authorization: `Bearer ${this.discord.$auth.oauth_access_token}`,
"accept": "application/json",
"content-type": "application/json",
},
data: {
name: newChannelName,
},
});
return response.data;
},
});