我不知道为什么我的反应角色代码不起作用。如果有人可以帮助我,将不胜感激!
client.on('messageReactionAdd', async (reaction, person) => {
if (reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message: ', error);
return;
};
};
if (reaction.emoji.name == ':tools:') {
if (reaction.message.id === '769855387394375681')
var server = client.guilds.cache.get('769100711593771038');
let personMember = server.members.cache.get(person);
const devRole = server.roles.cache.get('769428024609079319')
personMember.roles.add(devRole);
};
});
client.on('message', message => {
return; //For now, gotta code more stuff later
});
消息功能可以缓存消息,以便机器人可以检测对该消息的反应,如果确实需要,则可以检测到Idk。
也没有错误,只是不会给我这个角色。
答案 0 :(得分:0)
您需要指定表情符号ID,而不仅仅是if语句中的ListItem
。您可以通过在Discord中键入表情符号,然后在其前面加上反斜杠来获得此功能。发送该消息,您将得到类似export default function ListScreen() {
const [selectedList, setSelectedList] = React.useState([])
const data = [
{id:0, name:'Bob', date: moment().format('MMM Do YYYY')},
{id:1, name:'George', date: moment().format('MMM Do YYYY')}
]
function itemSelected(id) {
const index = selectedList.indexOf(id)
if (index === -1) {
// if item isn't already selected, add id to list
setSelectedList([...selectedList, id])
} else {
// else if id is in list, remove id from array
setSelectedList(selectedList.filter(el => el !== id))
}
}
function renderItem({ item }) {
const selected = selectedList.includes(item.id)
return (
<ListItem
item={item}
onPress={() => itemSelected(item.id)}
selected={selected}
/>
)
}
return (
<View>
<FlatList
data={data}
renderItem={renderItem}
keyExtractor={({id}) => id && id.toString()}
/>
</View>
)
}
const ListItem = ({item, onPress, selected}) => {
const {date, name} = item
console.log('Item rendering') // this always gets called twice, no matter which item I tap on.
return (
<TouchableRipple onPress={onPress}>
<View style={selected ? styles.selected : styles.unselected}>
<Text>{name}</Text>
<Text>{date}</Text>
</View>
</TouchableRipple>
)
}
的信息。数字部分是您的ID。
编辑:您将需要执行:tools: