如何在Discord.js上的另一个文件中导出变量
我试图在discord.js中制作shifumi游戏来训练我的技能。
因此,我创建了创建游戏并设计我们的伴侣的命令。
const { MessageEmbed, MessageActionRow, MessageButton, Permissions} = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('shifumi')
.setDescription('Play to shifumi with another user')
.addUserOption(option =>
option.setName('player')
.setDescription('The player you want to play with')
.setRequired(true)),
async execute(interaction) {
exports.userMain = interaction.user;
exports.userPlayer = interaction.options.getUser('player');
const shifumiEmbed = new MessageEmbed()
.setColor('#00B9FF')
.setTitle("Shifumi")
.setDescription('Indiquez la finalisation de votre exercice en cliquant sur le bouton ci-dessous.');
const rockButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('rock-button')
.setLabel('Pierre\ \ ')
.setStyle('PRIMARY')
.setEmoji('
Im trying to make a shifumi game in discord.js to train my skills.
So I created my command to create a game and design our mate.
const { MessageEmbed, MessageActionRow, MessageButton, Permissions} = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('shifumi')
.setDescription('Play to shifumi with another user')
.addUserOption(option =>
option.setName('player')
.setDescription('The player you want to play with')
.setRequired(true)),
async execute(interaction) {
exports.userMain = interaction.user;
exports.userPlayer = interaction.options.getUser('player');
const shifumiEmbed = new MessageEmbed()
.setColor('#00B9FF')
.setTitle("Shifumi")
.setDescription('Indiquez la finalisation de votre exercice en cliquant sur le bouton ci-dessous.');
const rockButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('rock-button')
.setLabel('Pierre\ \ ')
.setStyle('PRIMARY')
.setEmoji('????'),
);
const leafButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('leaf-button')
.setLabel('Feuille\ \ ')
.setStyle('PRIMARY')
.setEmoji('????'),
);
const scissorsButton = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('scissors-button')
.setLabel('Ciseaux')
.setStyle('PRIMARY')
.setEmoji('✂️'),
);
interaction.channel.send({ embeds: [shifumiEmbed], components: [rockButton, leafButton, scissorsButton]});
return interaction.reply({ content: `Game started !`, ephemeral: true });
},
};
And I need to use these variables :
userMain
userPlayer
Inside my rock-button.js file :
const { PermissionOverwrites, Permissions, Collection} = require("discord.js");
const shifumi = require("../../commands/shifumi.js");
module.exports = {
data: {
name: `rock-button`
},
async execute (interaction) {
// import userMain and userPlayer from the shifumi.js file
const { userMain, userPlayer } = shifumi;
console.log(userMain);
await interaction.reply({ content:'Information envoyée !', ephemeral: true});
}
}
I tried to use :
global.userMain = interaction.user;
global.userPlayer = interaction.options.getUser('player');
The result when I try to log the variable are undefined.
and ```js
exports.userMain
exports.userPlayer
But seems doesn't work to :/
I think we cant export a module when we already are in module but I can be wrong.
If somebody can help me I would appreciate :)
Ty
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)